mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Entity Creation and Destruction from scripts
- ScriptEngine: Allow destroying scripts during runtime
- Scripting:
- Create new entities using Constructors
- Added Destroy functions for Entities
- Added SetScript/RemoveScript functions for Entities
- Allow adding multiple components at once
- Added Is-Method
- Mono Wrapper: Added Array-Functions
- WorldEnumerator: Fixed crash due to dangling list pointer after entity creation
- Scene:
- Basic create Rigidbodies during runtime
- Start of entity copying (For runtime use)
- Added DestroyEntityDeferred
- SceneSerializer:
- Added option to assign new IDs to entities
This commit is contained in:
@@ -238,7 +238,7 @@ static class ScriptEngine
|
||||
{
|
||||
for (var entry in _entityScriptInstances)
|
||||
{
|
||||
entry.value.ReleaseRef();
|
||||
entry.value?.ReleaseRef();
|
||||
}
|
||||
_entityScriptInstances.Clear();
|
||||
|
||||
@@ -257,6 +257,9 @@ static class ScriptEngine
|
||||
script.Instance = new ScriptInstance(entityId, scriptClass);
|
||||
script.Instance..ReleaseRef();
|
||||
|
||||
if (_entityScriptInstances.TryGetValue(entityId, let currentInstance))
|
||||
currentInstance.ReleaseRef();
|
||||
|
||||
_entityScriptInstances[entityId] = script.Instance..AddRef();
|
||||
|
||||
script.Instance.Instantiate(entityId);
|
||||
@@ -264,6 +267,21 @@ static class ScriptEngine
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void DestroyInstance(Entity entity, ScriptComponent* script)
|
||||
{
|
||||
UUID entityId = entity.UUID;
|
||||
|
||||
if (script.Instance != null)
|
||||
script.Instance = null;
|
||||
|
||||
script.ScriptClassName = null;
|
||||
|
||||
if (_entityScriptInstances.TryGetValue(entityId, let currentInstance))
|
||||
currentInstance.ReleaseRef();
|
||||
|
||||
_entityScriptInstances[entityId] = null;
|
||||
}
|
||||
|
||||
public static void CopyEditorFieldsToInstance(Entity entity, ScriptComponent* script)
|
||||
{
|
||||
Log.EngineLogger.AssertDebug(script.Instance != null);
|
||||
|
||||
Reference in New Issue
Block a user