Can't access any members in CameraComponent when added from c++

Hi!

I have created a pawn in c++ and added an UCameraComponent to it.

header:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "PlayerPawn")
class UCameraComponent *Camera;

source (in constructor):

Camera = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT("PlayerCamera"));

However, for some reason I can’t edit the camera component’s default properties in the editor when making a blueprint class. The details tab were properties normally exists are completely empty for the camera component. If I add the camera component in the blueprint it works as usual. What may be the problem?

In “CameraActor.h” the code looks like this and works:

	UPROPERTY(Category = CameraActor, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
	class UCameraComponent* CameraComponent;

What visibility does your CameraComponent have? (Private/Protected/Public), I guess it should be public to be visible :slight_smile: (Though I’m not 100% sure about this …)

It’s public so shouldn’t be that, forgot to add that though.

It should be possible to have protected components editable also. Recently they added a restriction on having private editable members though, this will result in a compiling error as far as I know.

Can you try to create a new blueprint again with that class as a parent? I encountered this too though at some point … Not 100% sure what it was. Are you calling the code from above in the constructor ? (I assume so, as you have the ObjectInitializer, but who knows :wink: )

I am experiencing a similar issue right now. What engine version are you using? Can you try calling some function of an instance of that CameraComponent? For example, edit your Pawn blueprint to call Camera’s GetOwner on BeginPlay. It should crash because Camera is null.

At the risk of stating the very obvious here - in your example, the property is specified as “BlueprintReadOnly”. Have you tried “BlueprintReadWrite”?

I have posted my issue in a relevant thread.
Forum link

Ended up using a blueprint component instead.