Actor cannot have ChildActor of same class

Hey guys,

I just wanted to add a childactorcomponent of type ‘CustomActor’ to an Actor of the same Class.
After playing in the Editor I got an Error Message saying “Found cycle in child component…”
So I looked through the Source Code of ChildActorComponent and I found this in CreateChildActor()

if (Actor->GetClass() == ChildActorClass)
{
    bSpawn = false;
	UE_LOG(LogChildActorComponent, Error, 
           TEXT("Found cycle in child actor component '%s'. Not spawning Actor of class  '%s' to break."), *GetPathName(), *ChildActorClass->GetName());
}

I know this is to prevent a Stack Overflow, but what if I add a ChildActor through a specific Event??
I reproduced this Method and wrote it in my custom class and changed a bit here and there.
After trying my method the CustomActor managed to get a ChildActor of CustomActor.
It would be nice if you could implement another method like CreateChildActor(bool preventCycle); to let the user himsef decide if he wants to use that method.
I know it’s not a bug, but I don’t know which section this “Request” should be belonging to.

Sorry for my bad English.
By the way great Job to all Members of Epic. I Lover this Engine :smiley:

P.S.:
Is there maybe another way to create such Requests?

Put feture requests in feedback forum

Hey -

A feature request for this, UE-31216 , has been entered for consideration. As you mentioned, the reason the current implementation does not allow this behavior is to prevent an infinite loop. When the child is added to the parent, there would need to be a safeguard to prevent the child from adding an additional child of its own. Depending on what you are trying to accomplish, there may be other ways to achieve the same result.

Cheers

Hey thanks for your answer :slight_smile:
My attempt is to make a UserInterface with different Layout and Interactable Elements.
I impemented a VBox and HBox class which BaseClasses inherit from AActor.

Maybe it’s better that all my Elements derive from USceneComponent and add other Components like StaticMesh to represent them.

But I have another question:
Is there a way to attach Actors to Actors ChildActorComponent AND edit them in the Scene Outliner?
My Childs are spawned but I can’t select them in the Outliner which would be really cool.
I want to achieve in code something like this:

91819-example.png

Thanks :slight_smile:

Greetings

Thank you :slight_smile:

If you set an actor as a child actor component then add an instance of that class to the level, you should be able to select the actor instance in the outliner and the select the child actor component from the details panel for that particular instance.

Yeah I create my ChildActorComponents dynamically (In OnConstruction) and it doesn’t work :confused:
But I just saw that when I create a Childactorcomponent in a Childactorcomponent I can select the first child when pressing the second one.

Actor
   -Child  (<- Click on Child in Outliner focuses Actor)

Actor
    -Child
        -Child2 (<-Click on Child2 focuses Child which can be edited now)

I would say that this is a bug

Thanks so far for your answers :slight_smile: