Spawn actor with widget interaction component by template

Hi!

There is a problem to spawn actor by template if it has widget interaction component inside.
Callstack:

LogOutputDevice: Error: === Handled ensure: ===
LogOutputDevice: Error: Ensure condition failed: !bRegistered [File:C:\UnrealEngine\Engine\Source\Runtime\Engine\Private\Components\SceneComponent.cpp] [Line: 1595]
LogOutputDevice: Error: SetupAttachment should only be used to initialize AttachParent and AttachSocketName for a future AttachTo. Once a component is registered you must use AttachTo.
LogOutputDevice: Error: Stack: 
LogOutputDevice: Error: [Callstack] 0x0000000004002386 UE4Editor-Core.dll!FWindowsPlatformStackWalk::StackWalkAndDump() [c:\unrealengine\engine\source\runtime\core\private\windows\windowsplatformstackwalk.cpp:200]
LogOutputDevice: Error: [Callstack] 0x0000000003DA121A UE4Editor-Core.dll!FDebug::EnsureFailed() [c:\unrealengine\engine\source\runtime\core\private\misc\assertionmacros.cpp:298]
LogOutputDevice: Error: [Callstack] 0x0000000003DBB8E6 UE4Editor-Core.dll!FDebug::OptionallyLogFormattedEnsureMessageReturningFalse() [c:\unrealengine\engine\source\runtime\core\private\misc\assertionmacros.cpp:425]
LogOutputDevice: Error: [Callstack] 0x00000000EDC28157 UE4Editor-Engine.dll!USceneComponent::SetupAttachment() [c:\unrealengine\engine\source\runtime\engine\private\components\scenecomponent.cpp:1595]
LogOutputDevice: Error: [Callstack] 0x00000000EDBED5EF UE4Editor-Engine.dll!USceneComponent::AttachToComponent() [c:\unrealengine\engine\source\runtime\engine\private\components\scenecomponent.cpp:1672]
LogOutputDevice: Error: [Callstack] 0x00000000FF5B2C46 UE4Editor-UMG.dll!UWidgetInteractionComponent::UWidgetInteractionComponent() [c:\unrealengine\engine\source\runtime\umg\private\components\widgetinteractioncomponent.cpp:38]
LogOutputDevice: Error: [Callstack] 0x00000000018F0420 UE4Editor-CoreUObject.dll!StaticConstructObject_Internal() [c:\unrealengine\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:3151]
LogOutputDevice: Error: [Callstack] 0x00000000018F126E UE4Editor-CoreUObject.dll!StaticDuplicateObjectEx() [c:\unrealengine\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:1979]
LogOutputDevice: Error: [Callstack] 0x00000000018F0C57 UE4Editor-CoreUObject.dll!StaticDuplicateObject() [c:\unrealengine\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:1946]
LogOutputDevice: Error: [Callstack] 0x00000000ED6D988B UE4Editor-Engine.dll!AActor::CreateComponentFromTemplate() [c:\unrealengine\engine\source\runtime\engine\private\actorconstruction.cpp:910]
LogOutputDevice: Error: [Callstack] 0x00000000EE5016F8 UE4Editor-Engine.dll!USCS_Node::ExecuteNodeOnActor() [c:\unrealengine\engine\source\runtime\engine\private\scs_node.cpp:97]
LogOutputDevice: Error: [Callstack] 0x00000000EE501C8B UE4Editor-Engine.dll!USCS_Node::ExecuteNodeOnActor() [c:\unrealengine\engine\source\runtime\engine\private\scs_node.cpp:187]
LogOutputDevice: Error: [Callstack] 0x00000000EE501FEE UE4Editor-Engine.dll!USimpleConstructionScript::ExecuteScriptOnActor() [c:\unrealengine\engine\source\runtime\engine\private\simpleconstructionscript.cpp:609]
LogOutputDevice: Error: [Callstack] 0x00000000ED6E4654 UE4Editor-Engine.dll!AActor::ExecuteConstruction() [c:\unrealengine\engine\source\runtime\engine\private\actorconstruction.cpp:725]
LogOutputDevice: Error: [Callstack] 0x00000000ED6EA0A5 UE4Editor-Engine.dll!AActor::FinishSpawning() [c:\unrealengine\engine\source\runtime\engine\private\actor.cpp:2924]
LogOutputDevice: Error: [Callstack] 0x00000000ED70DDBE UE4Editor-Engine.dll!AActor::PostSpawnInitialize() [c:\unrealengine\engine\source\runtime\engine\private\actor.cpp:2867]
LogOutputDevice: Error: [Callstack] 0x00000000EDFB68C7 UE4Editor-Engine.dll!UWorld::SpawnActor() [c:\unrealengine\engine\source\runtime\engine\private\levelactor.cpp:468]
LogOutputDevice: Error: [Callstack] 0x00000000EDFB6CA7 UE4Editor-Engine.dll!UWorld::SpawnActor() [c:\unrealengine\engine\source\runtime\engine\private\levelactor.cpp:293]

After some debugging it looks like during spawning a new actor’s components it creates new widget interaction component which has it’s own Arrow component. Arrow component isn’t created as a new one - it’s found by hash. So the founded object had already been registered.

Update: I tested it with spawning character. In case of average actor (steps to reproduce are below) it just gets the hashed widget interaction component with already registered arrow component. After that it tries to attach it and crashes. Can it be connected with !IsTemplate() check?

You can reproduce this bug by:

  1. Write BluprintCallable function to spawn actor by template:
  2. FActorSpawnParameters SpawnInfo; SpawnInfo.Template = ActorToClone; AActor* ClonedActor= GetWorld()->SpawnActor(ActorToClone->GetClass(), GetActorLocation(), GetActorRotation(), SpawnInfo);
  3. Create actor with static mesh and widget interaction component.
  4. Place it to the level
  5. Bind a button to trace the placed object and call the function above.

How should I fix this problem? Should this component be hashed? If yes, should I add some extra checks before engine calling SetupAttachment? Is it okay that the new cloned actor will have the same component (as I understood)? Thank you!

Regards,
Ivan