Hello !
Context
I’m currently trying to work with Actors that need a Primitive Component directly as their root.
The thing is, I don’t know whether that Primitive Component is for a Static Mesh or for a Skeletal Mesh beforehand. It depends on external parameters, and may change with each instance of the Actor class.
Now, since UPrimitiveComponent is abstract, I can’t create it as a subobject in the Actor constructor, and define it as the root there. So what I’m doing instead is :
- dynamically creating the correct Component with NewObject when I do know what specialized class I want
- making sure it gets owned by my Actor, registered in the world, etc.
- setting is as the new root, while reworking the rest of the Component hierarchy to fit my needs
This strategy works quite well, as long as my Actors are instantiated dynamically.
But then I tried to serialize them into Blueprint Actors, and that’s when it started to get tricky.
Issue
First, it seems like the Primitive Component doesn’t get saved as the root inside the BP. I had to act on PostInitializeComponents to enforce the Component hierarchy I really wanted. Not ideal (because it’s called a lot) but at least, the Blueprints seemed to be okay, like this.
And then I discovered that adding a new C++ scene component, as a subobject of my class, would break the hierarchy shown in editor.
Here’s what I observe in more details :
- The additional scene component subobject, even if not set as root, becomes the first root anyway because of FixupNativeActorComponents. So far, I get why, and it’s not supposed to be an issue.
- The code I put on PostInitializeComponents is called, and - seemingly - manages to fix the hierarchy. It does set the Primitive Component as the root, and the additional scene component as a child.
- But the editor still shows the scene component subobject as the root. It’s simply not showing the structure I observe through my debugger, or even through logs…
Questions
Well, first, why do I get different truths from the editor and the debugger/logs, when it comes to the Component hierarchy?
Also, is there any other safe way for me to generate those Blueprints while inheriting from a class that doesn’t want to specify the exact type of its root Component? Any workaround?
Thanks for your answers.