Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

OnComponentCreated not called when using CreateDefaultSubobject?


I have an actor which has a native ChildActorComponent, declared in the C++ header like so :

 UPROPERTY( Category = Hoop, VisibleAnywhere )
 TSubobjectPtr< UChildActorComponent > PlayerStartCompnent;

This component is created in the constructor of the parent class :

     const class FPostConstructInitializeProperties& PCIP
     ) : 
     Super( PCIP )
     MeshComponent= PCIP.CreateDefaultSubobject< UStaticMeshComponent >( this, TEXT( "MeshComp" ) );

     RootComponent = MeshComponent;

     PlayerStartCompnent = PCIP.CreateDefaultSubobject< UChildActorComponent >( this, TEXT( "PlayerStartComponent" ) );
     PlayerStartCompnent->ChildActorClass = APlayerStart::StaticClass();
     PlayerStartCompnent->AttachTo( MeshComponent );

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?


Product Version: Not Selected
more ▼

asked May 08 '14 at 01:26 PM in Bug Reports

avatar image

172 21 30 35

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort oldest

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.

more ▼

answered May 08 '14 at 02:31 PM

avatar image

Marc Audy STAFF
2.2k 42 35 95

avatar image Zoubi May 08 '14 at 03:09 PM

The problem is that PostSpawnInitialize is called for the various gamestates, bots, controllers, and so on, but it is not called for this actor, which is in fact a BluePrint placed in the world.

The class owns a static mesh and 4 child actor components (all of the same type : APlayerSTart)

I saw in AActor.h that I can use PostActorCreated if the actor is spawned, and POstLoad if the actor is serialized, which I think is my case.

So, should I manually call OnComponentCreated on each of the 4 playerstart in PostLoad, as it doesn't seem to be called anyway?

I still think this should be automatically called, whether the actor has been spawned or deserialized, don't you think?

avatar image Marc Audy STAFF May 08 '14 at 08:06 PM

Ok, I believe I see what you're referring to now. If the ChildActorComponent is a native component and it is placed in the world then you never get the OnComponentCreated call, which is, I agree, bad and a bug.

I've entered the bug in our system, I'm not quite sure where the right spot to make sure it gets called from is, but we'll get it worked out.

Thanks for the report.

avatar image Zoubi May 09 '14 at 08:23 AM

I tried to call DispatchOnComponentsCreated in the POstLoad function, and didn't get any problems

avatar image Zoubi May 22 '14 at 09:27 PM


do you know if this bug is fixed in the upcoming 4.2 release?

avatar image Marc Audy STAFF May 22 '14 at 09:33 PM

I'm afraid it is not. I am currently working on hardening Child Actor Component but those changes should come in 4.3. I will provide you with a github link to the fix for this specific issue once it is submitted.

avatar image Zoubi May 22 '14 at 09:44 PM

OK, Thanks for your reply.

It's not urgent at all, I'm looking forward for your github link

avatar image Marc Audy STAFF Jun 06 '14 at 05:20 PM

Hello again Zoubi. The blueprint side of child actor component has been hardened and I was coming back around to this issue and I'm wondering whether in 4.2 the issues you were seeing are still present? While OnComponentCreated is still not called, I don't think that is a problem any more in 4.2 because the ChildActor pointer is no longer transient.

Let me know if you still think that there is an issue that needs resolving her or not as I'm currently leaning towards a feeling that it is working correctly.

avatar image Zoubi Jun 18 '14 at 09:33 AM


sorry for the late reply.

In my code, I used (with the 4.1 release) to add a call to OnComponentCreated in the PostLoad function of my parent actor, in order for the ChildActor pointer to be set.

I've commented all this code, with the 4.2 release, and indeed it does work.

So I would say it is fixed for me :)

BTW, I compared ChildActorComponent.h between the 4.1 and 4.2 releases, and the only relevant change is the UPROPERTY declaration above ChildActor.

What's the difference between DuplicateTransient (4.1) et NonPIETransient (4.2)?


avatar image Marc Audy STAFF Jun 18 '14 at 01:19 PM

There are too many kinds of transient :P

Transient: This means that the variable will not be saved, in the case of child actor component this would have meant the actor remained in the world but the reference to it lost.

DuplicateTransient: This means when we duplicate the object (such as we do for PIE), the value is not copied over. This similarly meant that while the Child Actor remained in the Level when we PIE (due to it also being duplicated), the reference to it was lost.

NonPIETransient: This is the opposite of DuplicateTransient. It means it should be transient unless we are duplicating for PIE (this was my first try at the fix, but it only fixed the PIE case and saving for standalone was still broken).

And finally TextExportTransient (which is what it should be in 4.2): Says that when we do a text export (which is what happens when we copy/paste), don't copy the value. Without this value when we duplicated the ChildActorComponent we ended up with 2 components pointing to the same Actor because the copy paste doesn't include the ChildActor.

avatar image VSZ Dec 19 '14 at 07:06 PM

Hi Marc, I'm wondering if this has been broken again. In 4.5 I'm able to reproduce exactly the kind of behavior that Zoubi is describing - i.e. my ChildActor is null unless I manually call OnComponentCreated. There seem to be quite a few questions on AnswerHub that are pointing to the same thing (see links below where people are attempting to call CreateChildActor manually because their child actor is not being automatically created). https://answers.unrealengine.com/questions/90283/unresolved-externals-error-with-uchildactorcompone.html https://answers.unrealengine.com/questions/131709/lnk-2019-createchildactor.html https://answers.unrealengine.com/questions/101002/uchildcomponentactor-createchildactor-compile-erro.html

For some background on my usecase - I'm porting some of my Blueprints to C++ and I have a 'builder' blueprint actor that generates many child actors dynamically. I was using SpawnActor at first and trying to parent it to my actor (by setting owner/ParentComponentActor/attachactortoactor/etc) but this didn't seem to work. Fortunately UChildActorComponent does exactly what my Blueprints did once I apply the OnComponentCreated workaround.

avatar image Alexander Paschall ♦♦ EPIC Feb 13 '15 at 07:13 PM


That issue seems to be related to a known bug (UE-6932) that started in 4.6.1. We are aware of the issue and a developer has reviewed and prioritized it. I have added a note that this is affecting many users and needs to be fixed as soon as possible. Thank you for your report.

avatar image Zoubi Apr 22 '15 at 07:32 PM


is this bug going to be resolved any time soon?

I'm unfortunately experiencing this bug with a builder blueprint I tried to port to C++ as well.


avatar image Doug E ♦♦ STAFF May 01 '15 at 02:28 PM

Hey Zoubi-

The bug report that Alexander mentioned is still being worked on by a developer. I'm unsure of the exact time frame for a fix but this issue is getting attention and should be fixed in a future update to the engine.

avatar image Zoubi Jun 18 '14 at 02:13 PM

Thanks for your explanations

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question