diff --git a/Engine.Core/Abstract/ITransform.cs b/Engine.Core/Abstract/ITransform.cs
index 724bc4a..f78adb8 100644
--- a/Engine.Core/Abstract/ITransform.cs
+++ b/Engine.Core/Abstract/ITransform.cs
@@ -6,7 +6,7 @@ namespace Syntriax.Engine.Core.Abstract;
///
/// Represents the transformation properties of an object such as position, scale, and rotation.
///
-public interface ITransform : IEnumerable
+public interface ITransform : IAssignableGameObject, IEnumerable
{
///
/// Event triggered when the of the changes.
diff --git a/Engine.Core/Factory/GameObjectFactory.cs b/Engine.Core/Factory/GameObjectFactory.cs
index f53ea9e..6713d39 100644
--- a/Engine.Core/Factory/GameObjectFactory.cs
+++ b/Engine.Core/Factory/GameObjectFactory.cs
@@ -22,6 +22,9 @@ public class GameObjectFactory
behaviourController ??= TypeFactory.Get();
stateEnable ??= TypeFactory.Get();
+ if (!transform.Assign(gameObject))
+ throw AssignException.From(transform, gameObject);
+
if (!behaviourController.Assign(gameObject))
throw AssignException.From(behaviourController, gameObject);
if (!stateEnable.Assign(gameObject))
diff --git a/Engine.Core/Transform.cs b/Engine.Core/Transform.cs
index 4a0c54d..6007b34 100644
--- a/Engine.Core/Transform.cs
+++ b/Engine.Core/Transform.cs
@@ -6,9 +6,13 @@ using Syntriax.Engine.Core.Abstract;
namespace Syntriax.Engine.Core;
-[System.Diagnostics.DebuggerDisplay("Position: {Position.ToString(), nq}, Scale: {Scale.ToString(), nq}, Rotation: {Rotation}")]
+[System.Diagnostics.DebuggerDisplay("Name: {GameObject.Name, nq} Position: {Position.ToString(), nq}, Scale: {Scale.ToString(), nq}, Rotation: {Rotation}")]
public class Transform : ITransform
{
+ public Action? OnGameObjectAssigned { get; set; } = null;
+
+ public Action? OnUnassigned { get; set; } = null;
+
public Action? OnPositionChanged { get; set; } = null;
public Action? OnScaleChanged { get; set; } = null;
public Action? OnRotationChanged { get; set; } = null;
@@ -28,6 +32,7 @@ public class Transform : ITransform
private readonly List _children = [];
+ public IGameObject GameObject { get; private set; } = null!;
public ITransform? Parent { get; private set; } = null;
public IReadOnlyList Children => _children;
@@ -245,4 +250,24 @@ public class Transform : ITransform
else
_rotation = Parent.Rotation + LocalRotation;
}
+
+ public bool Assign(IGameObject gameObject)
+ {
+ if (GameObject is not null && GameObject.Initialized)
+ return false;
+
+ GameObject = gameObject;
+ OnGameObjectAssigned?.Invoke(this);
+ return true;
+ }
+
+ public bool Unassign()
+ {
+ if (GameObject is not null && GameObject.Initialized)
+ return false;
+
+ GameObject = null!;
+ OnUnassigned?.Invoke(this);
+ return true;
+ }
}