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"

RootComponent variable for Actors which never had CreateDefaultSubobject invoked is null

This includes actors where the entire hierarchy is defined in BP, like ones that just inherit from a C++ AActor derivative whose constructor never calls CreateDefaultSubobject or sets RootComponent itself. Having RootComponent be null means that AActor::AttachRootComponentTo will do nothing, which is used in ChildComponentComponent to attach the Child actors to the parent.

Product Version: UE 4.8
more ▼

asked Aug 15 '15 at 09:15 AM in Bug Reports

avatar image

188 24 31 145

avatar image Doug E ♦♦ STAFF Aug 18 '15 at 04:11 PM

Hey rajkosto-

Could you elaborate on exactly what is happening? After setting up the hierarchy for the blueprint (who's parent was a custom actor class), with DefaultSceneRoot as the root component, I added an instance to the level and when printing the display name of the root component saw DefaultSceneRoot printed to the screen. Where are you seeing the root component being set to null?

avatar image rajkosto Aug 18 '15 at 04:14 PM

Try setting it as a class in a ChildActorComponent, then breakpoint inside UChildActorComponent::CreateChildActor on the ChildActor->AttachRootComponentTo line. Inside that function you will see that RootComponent is nullptr and the Child Actor doesn't actually get attached. Worked around this problem by having my native AActor do CreateDefaultSubobject with a USceneComponent and set it as its root in its constructor. The problem only occured when my native AActor had an empty constructor (with FObjectInitializer), and all the hierarchy was set up in the blueprint inheriting it.

avatar image Doug E ♦♦ STAFF Aug 20 '15 at 02:56 PM

I'm not sure I understand what you're doing. Are you creating a blueprint based on a custom class or adding a custom component to a blueprint? Could you explain your steps to reproduce the null root component as well as post the code that you've used in your setup?

avatar image rajkosto Aug 20 '15 at 07:05 PM
 UCLASS(Abstract,Blueprintable,Meta = (ChildCanTick))
 class AClimbable : public AActor
 AClimbable::AClimbable(const FObjectInitializer& PCIP) : Super(PCIP)  {}

Then make a blueprint inheriting from it, create a new scene component as the root, named it RootComp, add some other components below it.

Now try and spawn that blueprint as a ChildActorComponent in some other actor. It won't attach to its parent.

avatar image Doug E ♦♦ STAFF Aug 20 '15 at 08:17 PM

Hey rajkosto-

Here at the steps that I took:

  1. Create new Actor class (using the setup you posted) and compile

  2. Create a blueprint of this class (MyActorBP)

  3. In MyActorBP I added scene component as root component (RootComp) and a capsule component and static mesh component

  4. Created a new blueprint based on Actor (SpawningBP)

  5. In SpanwingBP I was able to add a child actor component and set it to MyActorBP (not sure if this is what you are doing)

Are you referring to creating MyActorBP as a child component during runtime? If so can you post the blueprint setup you use to do so?

avatar image rajkosto Aug 20 '15 at 09:23 PM

Is the child actor properly attached ? What is RootComponent inside that function if you run in debug mode and place a breakpoint where i said ?

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

2 answers: sort voted first

Hey rajkosto-

Could you explain how exactly this is affecting you? I put a breakpoint where you indicated and the RootComponent variable in the function was reporting NULL however the ChildActorComponent in the blueprint was setup properly(set MyActorBP as the Child Actor Class). I noticed the same result when attaching a blueprint based on Actor (no code) in the same way. Additionally if I print the components of the child actor components it gives me all of the components of MyActorBP in the correct hierarchy order.

alt text

more ▼

answered Aug 21 '15 at 07:50 PM

avatar image rajkosto Aug 21 '15 at 11:30 PM

Well if the RootComponent is null in that function...it means it won't attach. So try moving around the actor with the child component, the child actor won't follow.

avatar image Doug E ♦♦ STAFF Aug 24 '15 at 03:21 PM

When moving the SpawningBP instance in the level the child actor component moved along with it. Adding a simple function to move the actor in the SpawningBP blueprint also moved the child actor component during runtime.

Please explain how this issue is affecting you so I have an understanding of what you're seeing and what I should be looking for.


Doug Wilson

avatar image rajkosto Aug 24 '15 at 03:23 PM

Mine doesn't attach. Getting AttachParent of the newly spawned actor gives me null.

avatar image Doug E ♦♦ STAFF Aug 24 '15 at 04:06 PM

How are you getting the attached parent? Using the Get Attach Parent node in blueprint will return the SceneComponent that the target is attached to. Attaching an "Is Valid" node shows that if the target has a parent component (is not the root) then the check will be true and it will return that parent. If the target does not have a parent (target is the root component) then the Is Valid check will fail. This was the case in both the MyActorBP as well as the SpawwningBP when setting the root component as the target. In the case of the ChildActorComponent, it returns the default scene component of my SpawningBP (because I never changed this component).

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

Actually, when in C++, this can cause a real headache if you're relying on AttachToActor to programatically create an Actor hierarchy. I ended up using the following code to force initialize a root component.

void ARootWidget::PostInitializeComponents() { Super::PostInitializeComponents();

 if (!RootComponent)
     USceneComponent* SceneLayout = NewObject<USceneComponent>(this, TEXT("SceneLayout"));

     SceneLayout->OnComponentCreated(); // Might need this line, might not.



more ▼

answered Jun 03 '18 at 02:35 PM

avatar image

41 1 4 6

avatar image DanHollingsworth Nov 05 '18 at 11:33 PM

I have the same issue. Where the BP is getting spawned, and the aactor* returned from the spawn function has a null RootComponent()..

This is crashing in some code, and just breaking other.

The funny thing is, its working fine on other machines in the studio.

avatar image DanHollingsworth Nov 06 '18 at 06:01 PM

For me this turned out to be a corrupt Asset. You really never should get an actor in world that does not have a RootComponent. You should get warnings that one did not exist, and that one has been assigned.

The code above may have fixed the issue. But if the file was corrupt, who is to say how far the corruption went?

If you encounter this issue, you should probably roll back to a working version of the asset, (if you have source control). Or create the asset again from scratch if you dont.

(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