I have an actor type that has a custom ActorComponent in it, placed using the actor editor.
When I spawn that actor in the world using C++ code, the actor is spawned, i see the model appearing but the component’s InitializeComponent method isn’t called.
Should I be taking extra steps to ensure InitializeComponent is called?
I tried actor->RegisterAllComponents wondering if it would force component initialization but I made no difference.
I ran into a similar issue. This was tricky to fix. Here are the things I did to get it to work. You may need to do one or more of these:
Needed to use const FObjectInitializer constructor not default constructor since UE4 did not call default constroctor.
Needed to do stuff in InitializeComponent not constroctor. I think the constroctor is called once when you put an object in the map or something. Stuff that you want to happen each game probably should go in InitializeComponent.
Needed to set bWantsInitializeComponent to true in constroctor so that InitializeComponent is called.
Needed to clean out binaries directory for things to work right. Delete everything in Binaries since compiling C++ doesn’t always cause that to be refreshed properly.
It’s been sorted now, the issue wasn’t actually related to this, the actual problem was that the intended class was not being instanced, the base class was.
But all of these are good pointers to look at when instantiating a component.