Duplicate actor - Crashes, unexpected behaviour

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.

UE4Editor-Engine.dll!USceneComponent::UpdateComponentToWorldWithParent(USceneComponent * Parent, FName SocketName, bool bSkipPhysicsMove, const FQuat & RelativeRotationQuat, ETeleportType Teleport) Line 354 C++
UE4Editor-Engine.dll!USceneComponent::UpdateComponentToWorld(bool bSkipPhysicsMove, ETeleportType Teleport) Line 697 C++
UE4Editor-Engine.dll!USceneComponent::UpdateChildTransforms(bool bSkipPhysicsMove, ETeleportType Teleport) Line 1790 C++
UE4Editor-Engine.dll!USceneComponent::PropagateTransformUpdate(bool bTransformChanged, bool bSkipPhysicsMove, ETeleportType Teleport) Line 490 C++
UE4Editor-Engine.dll!USceneComponent::UpdateComponentToWorldWithParent(USceneComponent * Parent, FName SocketName, bool bSkipPhysicsMove, const FQuat & RelativeRotationQuat, ETeleportType Teleport) Line 403 C++
UE4Editor-Engine.dll!USceneComponent::UpdateComponentToWorld(bool bSkipPhysicsMove, ETeleportType Teleport) Line 697 C++
UE4Editor-Engine.dll!USceneComponent::UpdateChildTransforms(bool bSkipPhysicsMove, ETeleportType Teleport) Line 1790 C++
UE4Editor-Engine.dll!USceneComponent::PropagateTransformUpdate(bool bTransformChanged, bool bSkipPhysicsMove, ETeleportType Teleport) Line 490 C++
UE4Editor-Engine.dll!USceneComponent::UpdateComponentToWorldWithParent(USceneComponent * Parent, FName SocketName, bool bSkipPhysicsMove, const FQuat & RelativeRotationQuat, ETeleportType Teleport) Line 403 C++
UE4Editor-Engine.dll!USceneComponent::UpdateComponentToWorld(bool bSkipPhysicsMove, ETeleportType Teleport) Line 697 C++
UE4Editor-Engine.dll!UActorComponent::OnRegister() Line 640 C++
UE4Editor-Engine.dll!USceneComponent::OnRegister() Line 425 C++
UE4Editor-Engine.dll!UPrimitiveComponent::OnRegister() Line 391 C++
UE4Editor-Engine.dll!UActorComponent::ExecuteRegisterEvents() Line 1094 C++
UE4Editor-Engine.dll!UActorComponent::RegisterComponentWithWorld(UWorld * InWorld) Line 871 C++
UE4Editor-Engine.dll!AActor::IncrementalRegisterComponents(int NumComponentsToRegister) Line 3808 C++
UE4Editor-Engine.dll!AActor::RegisterAllComponents() Line 3747 C++
UE4Editor-Engine.dll!AActor::PostSpawnInitialize(const FTransform & UserSpawnTransform, AActor * InOwner, APawn * InInstigator, bool bRemoteOwned, bool bNoFail, bool bDeferConstruction) Line 2603 C++
UE4Editor-Engine.dll!UWorld::SpawnActor(UClass * Class, const FTransform * UserTransformPtr, const FActorSpawnParameters & SpawnParameters) Line 441 C++
UE4Editor-Engine.dll!UWorld::SpawnActor(UClass * Class, const FVector * Location, const FRotator * Rotation, const FActorSpawnParameters & SpawnParameters) Line 267 C++
UE4Editor-Game.dll!UGamePlayerInventory::Take(AGameInventoryItem * Item, bool bGrab) Line 76 C++

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)