StaticMesh garbage collection issue

Hey, wondering if anyone can help me with this garbage collection issue I have. I have a class derived directly from USceneComponent, therefore also derived from UObject, that contains a static mesh variable that is assigned in the blueprint details panel. The variable is defined as below using UPROPERTY:


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Mesh)
UStaticMesh* Mesh;

I use this mesh reference to pass to other systems such as particles and this works perfectly in the editor, but when I make a build I always get a crash caused by garbage collection with an error like this:

“ParticleSystem is referencing StaticMesh which is not part of root set or cluster.”

I can fix this by adding Mesh->AddToRoot(); but I was hoping someone here knows why this mesh is being garbage collected in the first place. My understanding is that UPROPERTY should stop it being garbage collected as long as it can be found from an object that is part of a root set, which I think my class should be since the blueprint it belongs to is placed in the level.

Any help would be greatly appreciated.

You need to put the pointer into a container.

Check this doc

TimeBlades Could you please provide more details ?