diff --git a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp index 84421de7..7820b108 100644 --- a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp @@ -43,12 +43,12 @@ namespace Nuake { return scene->GetEntity(entityName).GetHandle(); } - Coral::ManagedObject* GetEntityScriptFromName(Coral::String entityName) + void GetEntityScriptFromName(Coral::String entityName, Coral::ManagedObject* outInstance) { auto scene = Engine::GetCurrentScene(); if (!scene->EntityExists(std::string(entityName))) { - return nullptr; // Error code: entity not found. + // Error code: entity not found. } Entity entity = scene->GetEntity(entityName); @@ -57,9 +57,9 @@ namespace Nuake { if (scriptingEngine.HasEntityScriptInstance(entity)) { auto instance = scriptingEngine.GetEntityScript(entity); - return instance; + outInstance->m_Handle = instance->m_Handle; + outInstance->m_Type = instance->m_Type; } - } Coral::ManagedObject* GetEntityScriptFromHandle(int entityHandle) diff --git a/Nuake/src/Scripting/ScriptingEngineNet.cpp b/Nuake/src/Scripting/ScriptingEngineNet.cpp index d1dc4d21..8b1437d1 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/src/Scripting/ScriptingEngineNet.cpp @@ -660,7 +660,7 @@ namespace Nuake } } - entityToManagedObjects.emplace(entity.GetID(), classInstance); + // Override with user values set in the editor. for (auto& exposedVarUserValue : component.ExposedVar) @@ -726,6 +726,8 @@ namespace Nuake classInstance.SetFieldValue(exposedVarUserValue.Name, exposedVarUserValue.Value); } } + + entityToManagedObjects.emplace(entity.GetID(), std::move(classInstance)); } Coral::ManagedObject* ScriptingEngineNet::GetEntityScript(const Entity& entity) diff --git a/NuakeNet/src/Scene.cs b/NuakeNet/src/Scene.cs index 641432a0..ce25a1e1 100644 --- a/NuakeNet/src/Scene.cs +++ b/NuakeNet/src/Scene.cs @@ -7,16 +7,20 @@ namespace Nuake.Net public class Scene { internal static unsafe delegate* GetEntityIcall; - internal static unsafe delegate*> GetEntityScriptFromNameIcall; + internal static unsafe delegate**, void> GetEntityScriptFromNameIcall; internal static unsafe delegate*> GetEntityScriptFromHandleIcall; internal static unsafe delegate* InstancePrefabIcall; public static T? GetEntity(string entityName) where T : class { - NativeInstance handle; - unsafe { handle = GetEntityScriptFromNameIcall(entityName); } + NativeInstance handle; - Entity? entity = handle.Get(); + // This doesnt :( + unsafe { GetEntityScriptFromNameIcall(entityName, &handle); } + + + object? entity = handle.Get(); + Engine.Log("Fetched entityL: " + entity); if (entity != null && entity is T) { return entity as T;