Hello UE community, I have been facing a spawning issue these past days that I have not been able to resolve. I am working on a UE 4.27 VR project. I need to complete the following objectives:
- Spawn actor at specific locations
- give each actor a unique name (or get their unique name)
- Upon component overlap, get the unique name of each actor.
This is how I call the spawn:
World->SpawnActor<AActor>(ToSpawn, SpawnLocation, rotator, spawnParams);
I have also tried:
AActor *MySpawn = World->SpawnActor<AActor>(ToSpawn, SpawnLocation, rotator, spawnParams);
Both work.
Issue: Spawning works well, issue comes in when I try and rename the actor (derived from a blueprint class). When I run ToSpawn->Rename(xyz) OR MySpawn->Rename(xyz) (using second spawn line) the engine crashes and gives me the following error:
Rename error during regular spawn (from log file):
[2023.04.25-16.41.01:874][861]LogWindows: Error: Renaming an object (cone_C /Game/LWG_Levels/UEDPIE_0_LWG_A.LWG_A:PersistentLevel.cone_C_1) on top of an existing object (cone_C /Game/LWG_Levels/UEDPIE_0_LWG_A.LWG_A:PersistentLevel.NEWNAME) is not allowed
I tried using deferred spawn and renaming before the spawn was finished but got the same error shown above. The deferred spawn code is below:
AActor* MySpawn = World->SpawnActorDeferred<AActor>(ToSpawn, SpawnTransform);
if (MySpawn == nullptr) {
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::Printf(TEXT("MySpawn: Null")));
}
else {
MySpawn->Rename(TEXT("NEWNAME")); // crash
FString MySpawnNameString = MySpawn->GetName();
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, FString::Printf(TEXT("OName: %s"), *MySpawnNameString));
MySpawn->FinishSpawning(SpawnTransform); // deferred
}
I am not sure how to go around this issue. The goal is to retrieve the name shown when you hover over an object in the UE Editor.
Note: I am aware of ToSpawn->GetUniqueID() but this isn’t preferred because it generates a new ID every spawn and isn’t always the same. I guess I could use it if nothing else works and then I can attach it to the object for referencing later, but I wanted to see if renaming was possible before I did that.
Thanks in advance!