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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Bug with recreating an object that has subobjects

This came up as a result of mistakenly reusing the same name when spawning actors, however I believe there is nonetheless an underlying issue which should probably be looked at.

To repro, create an AActor derived class (named ATestActor in example below) with nothing added other than the following line in the constructor:

 RootComponent = CreateDefaultSubobject< USceneComponent >(TEXT("TestSceneComponent"));

Then trigger the following code from any context:

 auto World = GetWorld();
 FActorSpawnParameters Params;
 Params.Name = TEXT("MyTestActorName");
 World->SpawnActor< ATestActor >(Params);
 World->SpawnActor< ATestActor >(Params);

Clearly, reusing the same name like this is not something that should be done, however I suspect the results are not as intended. It will assert at check(!bHasBegunPlay); in UActorComponent::BeginPlay.

As far as I can see, calling NewObject with a name that already exists will recreate the object in place. However, there seems to be some issue with this process and subobjects - it seems they remain intact, giving rise to the above assertion failure.

At the very least, I think it would be a good idea to put a check for this scenario within SpawnActor and output a warning that the name has been reused.

Repro code: TestActor.h TestActor.cpp LevelBlueprint

Product Version: UE 4.9
more ▼

asked Oct 02 '15 at 07:32 PM in Bug Reports

avatar image

2.1k 83 34 119

avatar image Doug E ♦♦ STAFF Oct 05 '15 at 02:05 PM

Hey kamrann-

How are you triggering the code block posted? Where is this being triggered from? Are you adding this to the custom class along with the first line of code? Where are "World" "ATestActor" and "TheActorClass" coming from? What exactly is the error you're getting when doing this?


Doug Wilson

avatar image kamrann Oct 05 '15 at 04:38 PM

Hi Doug. I've edited the question to clarify a couple of the names used.

The context from which the block of code is triggered can be anywhere, for example, invoke it from the BeginPlay event of any actor, or the level blueprint. Regardless of where it's triggered from, calling SpawnActor multiple times using the same name, on an actor class which has components, will result in a crash - specifically the failed assert I mentioned.

avatar image Doug E ♦♦ STAFF Oct 05 '15 at 05:51 PM

I copied the "RootComponent" line into my actor class's constructor and the other code block into the BeginPlay() function. After compiling and placing an instance of the class into the level I was able to PIE without getting any crash. Does copying the code into a new actor class in a new project give you the assert you mentioned? If so let me know if there is something I've missed in my reproduction.

avatar image kamrann Oct 05 '15 at 06:53 PM

I meant to put the triggering code into the BeginPlay of something else. I would have thought spawning the actor from within it's own BeginPlay would have led to recursion problems.

Anyway, I've attached the code (on the original question) as I have it. This is all I've added to a blank project, along with the level blueprint set up as shown to trigger the spawning. No need to place an instance of the actor by hand.

avatar image LinkoVitch Dec 09 '16 at 02:23 PM

You can get this to occur if you call BeginPlay within an AActor derived C++ class too (After it's initial 1st call). I suspect that there is some initialisation / registration being done, and obviously the object has the same name as itself.

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

1 answer: sort voted first

Hey Kamrann-

I was able to reproduce the crash you mentioned and a bug report (UE-20951) has been entered for investigation.


Doug Wilson

more ▼

answered Oct 05 '15 at 07:40 PM

(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