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"

SetRootComponent directly after Spawn


try to switch the RootComponent directly after spawning an Actor:

 void ASpawner::BeginPlay()
     UWorld* World = GetWorld();
     FActorSpawnParameters SpawnInfo;
     SpawnInfo.Owner = GetOwner();
     SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
     AActor* SpawnedActor = World->SpawnActor<AActor>(SpawnedClass, SpawnInfo);
     //Get attached Component
     UActorComponent* FoundComponent = SpawnedActor->GetComponentByClass(UPrimitiveComponent::StaticClass());
     UPrimitiveComponent* CastComponent = Cast<UPrimitiveComponent>(FoundComponent);
     //Set as Root

The spawned ActorBlueprint looks like this:
alt text


I get the error message:
Ensure condition failed: ParentActor != ActorPtr ...
Encountered an Actor attached to itself


Is this a bug or do I need to register the Actor/Component/etc.?

Product Version: UE 4.21
spawned.jpg (17.8 kB)
more ▼

asked May 30 '19 at 05:27 PM in C++ Programming

avatar image

8 2 2 6

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

2 answers: sort voted first

I think you should set the RootComponent only in the actor's constructor.

Also it's not good at all to access an actor's components from another actors.

There is a way to make some setup for a spawning actor before spawn is completed, look hee for the upvoted answer. Though I'm sure it's still not the way to setup the actor's component. In most cases, components should be created in the actor's constructor.

more ▼

answered May 30 '19 at 06:32 PM

avatar image

440 11 18 28

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

Interesting, that function was new to me.

Using it doesn't trigger the ensure condition anymore, SetRootComponent returns a bool to indicate success, but it doesn't do anything.

I know that it is bad practice to modify unknown Actors from outside. The reason I require this functionality is actually to autocorrect mistakes that inexperienced designers may make when choosing certain configurations. Since the projects are usually short-lived, it is easier to throw a warning and try to guess what the intention of the designer was.

Unfortunately, I don't know how I could validate that SetRootComponent will crash by using Unreal's functionality and checking for certain conditions doesn't work since the involved entities don't know about each other.

more ▼

answered May 30 '19 at 07:59 PM

avatar image

8 2 2 6

(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