Download

adding a StaticMeshComponent to another custom SceneComponent derrived class

So, I am adding a SceneComponent to an another custom SceneComponent derrived class like so,

in header



UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "UI Indiactor")
class UStaticMeshComponent* ButtonIndicatorComp;
 

in cpp


UStaticMeshComponent* IndicatorComp = ConstructObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass(), this);
//IndicatorComp->AttachTo(this);
ButtonIndicatorComp = IndicatorComp; // pointer reference to be persist throughout the game.


And it seems to work but when I try to save… below error occurred.

What would be my best bet to go over this problem?

change your

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = “UI Indiactor”)

to
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = “UI Indiactor”, meta = (AllowPrivateAccess = “true”))

or put your property in the public section of your class

Hi Chooka,

changing the UPROPERTY like that is not changing the situation…

It was under the public as well…

Hey JaeYoo-

If the construction of the component is taking place inside the class constructor then you will want to use CreateDefaultSubobject instead of ConstructObject. Additionally, since you declared the ButtonIndicatorComp in your header file, you can use this in the construction call rather than creating a new pointer and then setting the new pointer to ButtonIndicatorComp.