Download

Expose a Static Mesh Component from Code

Hi,

I have created a class and I want to have a reference to a non-existent static mesh component. I mean… I create a blueprint from my c++ class and then I create a static mesh component in viewport. I want to reference this new static mesh component from code.

I have tried with:



protected:
	UPROPERTY(EditAnywhere)
	UStaticMeshComponent* MeshCmpRef;

and

	UPROPERTY(VisibleDefaultsOnly)
	UStaticMeshComponent* MeshCmpRef;



But I dont see the exposed variable. Where is the issue??

Thanks!!

You simply need to initialize your component in your actor constructor and attach it to root.
In this tutorial, he made it for a camera but, it’s exactly the same idea:

I hope this help you :slight_smile:

Thanks JackBlue!

I think that is not that i’m looking for… it’s hard to explain.

I want the static mesh component will be created from the blueprint, just using “Add Component->static mesh component” in the viewport. Then I want to have an exposed static mesh component pointer (null by default) and point to the static mesh component that I have created previously in the viewport.

I mean that all the CreateDefaultSubobject<…> stuff will be managed internal by the engine not in my code.

it’s difficult to explain in english for me… sorry.

Thanks again!