InitializeComponent not firing on spawn

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.

Thanks in advance.

1 Like

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:

  1. Needed to use const FObjectInitializer constructor not default constructor since UE4 did not call default constroctor.
  2. 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.
  3. Needed to set bWantsInitializeComponent to true in constroctor so that InitializeComponent is called.
  4. 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.

Good luck,
-X

3 Likes

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.

Step 3 was key for me. It did however make me feel very stupid.

2 Likes