OnComponentCreated not called when using CreateDefaultSubobject?
I have an actor which has a native ChildActorComponent, declared in the C++ header like so :
This component is created in the constructor of the parent class :
In the code, I want to access to the ChildActor property of UChildActorComponent. But this value is NULL.
To be initialized, the function UChildActorComponent::OnComponentCreated must be called, which is not the case. I put a breakpoint in this function, and never broke on it.
But the actor seems to be created anyway, because when I update the position of the actor in the editor, I can get the correct value when I call :
I suppose this is a bug, because using Blue prints, it seems that this function gets called.
Or do I have to manually call this function in the PostInitializeComponents function of the parent actor?
asked May 08 '14 at 01:26 PM in Bug Reports
OnComponentCreated is called as part of the Spawn process. In AActor::PostSpawnInitialize we dispatch the OnComponentsCreated call which does the set up, then they get registered.
If you want to manipulate the ChildActor from the owning Actor in code you should look at overriding PostActorCreated.
answered May 08 '14 at 02:31 PM
Marc Audy STAFF
Follow this question
Once you sign in you will be able to subscribe for any updates here