Hello,
I am trying to duplicate actor using FActorSpawnParameters. I have set up FActorSpawnParameters.Template to point to the original object to be spawned.
I have few streamed levels and I want to copy (or move) instance of my torch to Persistent level, to prevent it from being unloaded with streamed level together, when player has this torch in his hands. That’s why I want to respawn it using original object as template.
Spawning object this way is causing a lot of bugs. First of all, it crashes in “-game” mode on
Gamethread hitch waiting for resource cleanup on a UObject (%s) overwrite. Fix the higher level code so that this does not happen.
Second, it does not copy CollisionComponent properly, because copy of that actor is falling down through walls.
Regards,
Hey -
Can you show the code used when setting up your FActorSpawnParamters? It would be best if you could post the class you are doing this in. Additionally, can you provide the callstack and log files from the crash for additional information.
void UPlayerInventory::Take(AInventoryItem * Item)
{
if (IsFull())
{
return;
}
AInventoryItem * ItemToTake = Item;
if (!ItemToTake->GetLevel()->IsPersistentLevel())
{
FActorSpawnParameters SpawnParams;
SpawnParams.Template = ItemToTake;
// Queue old one to destroy.
ItemToTake->Destroy();
// Create using old one as template.
ItemToTake = (AInventoryItem*)(GetWorld()->SpawnActor<AInventoryItem>(Item->GetClass(), SpawnParams));
}
OwnedItems.Add(ItemToTake);
ItemToTake->OnTake();
SetActiveItem(ItemToTake);
}
Could you post the callstack and log files from the crash as well for additional information? Looking at the code itself, it appears that ItemToTake == Item. So SpawnParams.Template = ItemToTake;
is the same as SpawnParams.Template = Item;
. Thus when you attempt to spawn the new item using the SpawnParams, the template you’re using is a clone of the item that was passed into the function and may be causing a conflict (likely naming). Being able to look at the callstack and log files will help confirm if this is what is happening or if the issue is something else.
Hey -
I tried to setup a sample project but I am not getting a crash when I spawn the new actor. Can you provide your project so I can see the crash locally? If you remove the Saved and Intermediate folders, you can zip the project folder and post it here or you can upload it to google drive or dropbox and send me a private message on the forums with a download link for privacy.
Hi ,
We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.
Thank you.
I’ve eventually fixed this issue by skipping cloning actors. I move them to persistent level instead of clone and destroy.
Anyway, still there are a lot of troubles with SpawnActor’s template parameter. (UE 4.13)