diff --git a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.ScriptCanvasNodeable.xml b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.ScriptCanvasNodeable.xml
index d930e16057..b2f48fae5f 100644
--- a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.ScriptCanvasNodeable.xml
+++ b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.ScriptCanvasNodeable.xml
@@ -11,8 +11,15 @@
Namespace="ScriptCanvas"
Description="Spawn">
-
+
+
+
+
+
+ />
diff --git a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.cpp b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.cpp
index 5c72f60625..0e067b65bf 100644
--- a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.cpp
+++ b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.cpp
@@ -10,8 +10,11 @@
*
*/
+#pragma optimize("", off)
#include
+#include
+
namespace ScriptCanvas
{
namespace Nodeables
@@ -23,19 +26,73 @@ namespace ScriptCanvas
AZ::Data::AssetId cubeAssetId("{90552CB9-2F29-5A2E-976C-61BF7ADACB81}", 272062881);
m_spawnableAsset = AZ::Data::AssetManager::Instance().GetAsset(cubeAssetId, AZ::Data::AssetLoadBehavior::PreLoad);
AZ::Data::AssetManager::Instance().BlockUntilLoadComplete(m_spawnableAsset);
-
- m_spawnTicket = AzFramework::EntitySpawnTicket(m_spawnableAsset);
}
SpawnNodeable::SpawnNodeable(const SpawnNodeable& rhs)
{
m_spawnableAsset = rhs.m_spawnableAsset;
- m_spawnTicket = AzFramework::EntitySpawnTicket(rhs.m_spawnableAsset);
}
- void SpawnNodeable::Spawn()
+ void SpawnNodeable::OnInitializeExecutionState()
{
- AzFramework::SpawnableEntitiesInterface::Get()->SpawnAllEntities(m_spawnTicket);
+ m_spawnTicket = AzFramework::EntitySpawnTicket(m_spawnableAsset);
+ }
+
+ void SpawnNodeable::OnDeactivate()
+ {
+ m_spawnTicket = AzFramework::EntitySpawnTicket();
+ }
+
+ //void SpawnNodeable::Translation(Data::Vector3Type translation)
+ //{
+ // m_translation = translation;
+ //}
+
+ //void SpawnNodeable::Rotation(Data::Vector3Type rotation)
+ //{
+ // m_rotation = rotation;
+ //}
+
+ //void SpawnNodeable::Scale(Data::Vector3Type scale)
+ //{
+ // m_scale = scale;
+ //}
+
+ void SpawnNodeable::RequestSpawn(Data::Vector3Type translation, Data::Vector3Type rotation, Data::NumberType scale)
+ {
+ auto preSpawnCB = [this, translation, rotation, scale]([[maybe_unused]] AzFramework::EntitySpawnTicket& ticket,
+ AzFramework::SpawnableEntityContainerView view)
+ {
+
+ AZ::Entity* rootEntity = *view.begin();
+
+ AzFramework::TransformComponent* entityTransform =
+ rootEntity->FindComponent();
+
+ if (entityTransform)
+ {
+ AZ::Vector3 rotationCopy = rotation;
+ AZ::Quaternion rotationQuat = AZ::Quaternion::CreateFromEulerAnglesDegrees(rotationCopy);
+
+ entityTransform->SetWorldTM(AZ::Transform(translation, rotationQuat, AZ::Vector3(scale, scale, scale)));
+ }
+ };
+
+ auto spawnCompleteCB = [this]([[maybe_unused]] AzFramework::EntitySpawnTicket& ticket,
+ AzFramework::SpawnableConstEntityContainerView view)
+ {
+ AZStd::vector spawnedEntities;
+ spawnedEntities.resize(view.size());
+
+ for (const AZ::Entity* entity : view)
+ {
+ spawnedEntities.emplace_back(entity->GetId());
+ }
+
+ CallOnSpawn(spawnedEntities);
+ };
+
+ AzFramework::SpawnableEntitiesInterface::Get()->SpawnAllEntities(m_spawnTicket, preSpawnCB, spawnCompleteCB);
}
}
}
diff --git a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.h b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.h
index 1eb53d53a2..4d73449d58 100644
--- a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.h
+++ b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Libraries/Spawning/SpawnNodeable.h
@@ -34,6 +34,10 @@ namespace ScriptCanvas
SpawnNodeable(const SpawnNodeable& rhs);
+ void OnInitializeExecutionState() override;
+
+ void OnDeactivate() override;
+
private:
AZ::Data::Asset m_spawnableAsset;
AzFramework::EntitySpawnTicket m_spawnTicket;