I want to create my own component that I can drag&drop to my actors. For this I inherit from USceneComponent. To show the component I create some sub components (e.g. StaticMeshComponents) like that:
//Constructor(const FObjectInitializer& ObjectInitializer)
CompassMesh = CreateDefaultSubobject<UStaticMeshComponent>("CompassMeshComponent");
It was working fine. Then I added Steam multiplayer and needed to play in Standalone mode instead of PIE. I figured out that playing in Standalone gives me an instant crash. In the logs I got the following message:
For this problem I found
…] this particular error occurs when attempting to create a new object over an existing object that hasn’t been completely cleaned up. The most likely cause for this is that the new object is being created with the same name/class/outer as an existing component, when the existing object cannot immediately clean up its resources in BeginDestroy.
…] You should be able to get past this crash by making sure that the names of any new actors are different from any existing actors that may still be waiting to get cleaned up. If you can guarantee that the names of the new actors will always be unique they should spawn without any problems, and GC will take care of the old actors.
Unfortunately I have no idea what I need to do… I could taking a random number, cast to string and use that as a name. But this makes me feeling very bad since random != unique.
Can you help me?
How to fix “Gamethread hitch waiting for resource cleanup on a UObject (…) overwrite.” on class inherited from USceneComponent?
It seems to be caused by name collisions, objects with the same name. More details here:
[C++] SpawnActor Bug - C++ - Epic Developer Community Forums
Same here, I spawned Spline Mesh components dynamically in a loop and by simply not specifying the
FName Name parameter, the deluge of warnings disappeared:
USplineMeshComponent* SplineMesh = NewObject<USplineMeshComponent>(InParent);
The docs say
the name for the new object. If not specified, the object will be given a transient name via MakeUniqueObjectName
NewObject | Unreal Engine Documentation