How to assign component to Uproperty from within class defaults

In C++ I have this property for a component.


UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"), Category = "Attachment")
USceneComponent* SomeComponent;

In the engine, when I edit the property, I have a dropdown of component classes. When I select one it looks like it tries to create a new instance.

I’d instead like to drag one of the actor’s components in and set it that way. Or if the dropdown list had a list of components in the actor.

Is this possible? Unity has similar behavior which is kindof an essential Unity pattern.

In Unreal I can only think to do this in code like in a construction script which isn’t as user friendly.

Eyo,

I am not really sure what you mean but it sounds like you are looking for TSubclassOf.
Here is a Link:

It’s more like how it is in Unity here starting at 3:08.

You can assign existing object references to variables. I have an existing Component I want to assign to a variable. TSubclassOf is a way to tell the component what class to spawn at run time.

Oh,

Sorry, I misunderstood.

My Engine is currently building so I cannot check this in my CPP but I think what you are after is the UPROPERTY(Instanced)
Link: A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums

In Blueprint, you can access the value using by checking the box “Instance Editable”.

Done building and tried it out using
“UPROPERTY(Instanced, EditInstanceOnly)”
and it seemed to work out :slight_smile:

1 Like

Ooooh, OK. I think I tried Instanced but without EditInstanceOnly.

This is one of the more confusing parts. I’ve been wishing there was a youtube video explaining this in detail since reading about the property specifiers it isn’t clear enough. It still confuses me sometimes and I’ve been using Unreal 4 since 1.0

Good to know that it helped!

Yeah, I agree that it is a bit confusing.

Maybe you can use this page instead as I believe that it is more descriptive and generally have more information:

Hello,
Mind telling me why its not working in my case?


UPROPERTY(Instanced, EditInstanceOnly, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"), Category = Attachment)
	USceneComponent* SomeComponent;
	UPROPERTY(Instanced, EditInstanceOnly)
	USceneComponent* SomeComponent1;

None of them is showing in details panel in class defaults