Description

Attempting to return a const pointer from a UFUNCTION will cause a VS compile error

The syntax

UFUNCTION(BlueprintCallable, Category = test)
const UMyActorComp* SomeFunc();

returns a VS compile error (@ GENERATED_BODY line) stating

Cannot convert from 'const UMyActorComp*' to 'UMyActorComp*'

This is likely related to [Link Removed]

Steps to Reproduce
  1. Open UE4 Editor (any project)
  2. Add code to project based on Actor (MyActor)
  3. Add the following to MyActor.h
    UFUNCTION(BlueprintCallable, Category = test)
    const UStaticMeshComponent* SomeFunc();
    
  4. Add the following to MyActor.cpp
    const UStaticMeshComponent* AMyActor::SomeFunc()
    {
    	UStaticMeshComponent* Something;
    	return Something;
    }
    
  5. Compile

Result:
Compile fails with error mentioned in description

Expected:
Class compiles and UHT returns a const pointer

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-50745 in the post.

9
Login to Vote

Fixed
Fix Commit15018807
CreatedOct 4, 2017
ResolvedJun 9, 2021
UpdatedJun 9, 2021