Class LunyObject
Engine-agnostic wrapper for engine objects. Safeguards against NullReferenceExceptions when the engine-native object may have been destroyed.
public abstract class LunyObject : ILunyObject
Constructors
LunyObject(Object, Int64, Boolean, Boolean)
Instantiates a LunyObject instance.
protected LunyObject(Object nativeObject, Int64 nativeObjectId, Boolean isNativeObjectEnabled, Boolean isNativeObjectVisible)
Parameters
| Type | Name | Description |
|---|---|---|
nativeObject |
||
nativeObjectId |
||
isNativeObjectEnabled |
||
isNativeObjectVisible |
Properties
IsEnabled
Whether the engine object is processing and visible. Matches the "Active" state of Unity.
public Boolean IsEnabled { get; set; }
Property Value
- Boolean
Remarks
The object may be enabled, but still be disabled in the hierarchy due to a parent not being enabled. IsEnabled also toggles visibility. If the object's IsVisible was set to false, and then the object gets enabled, the object's IsVisible state will also change to true.
IsEnabledInHierarchy
Returns true only if BOTH the object itself AND all of its parents are enabled. Otherwise returns false.
public Boolean IsEnabledInHierarchy { get; }
Property Value
- Boolean
IsNativeObjectValid
Is true when Destroy() was called on the NativeObject and it was set to null.
public Boolean IsNativeObjectValid { get; }
Property Value
- Boolean
IsValid
Whether the object and its native representation are valid (not null, not destroyed).
public Boolean IsValid { get; }
Property Value
- Boolean
IsVisible
Whether the object is visible (will render).
public Boolean IsVisible { get; set; }
Property Value
- Boolean
Remarks
This property does NOT imply that the object is currently visible on screen. It is technically visible, but may still be outside the camera's frame, obstructed by other objects, fully transparent, scaled infinitely small, etc.
LunyObjectId
Unique, immutable identifier for LunyObject. This ID is distinct from engine's native object ID!
public LunyObjectId LunyObjectId { get; }
Property Value
Name
The name of the object in the scene hierarchy.
public String Name { get; set; }
Property Value
- String
Remarks
To aid debugging, this property remains valid even after the object has been destroyed.
NativeObject
Gets the underlying engine-native object (GameObject, Node) as generic System.Object type. Use the Cast<T>() or As<T>() methods to avoid manually casting the reference.
public Object NativeObject { get; }
Property Value
- Object
NativeObjectId
Engine-native object's unique, immutable identifier. Subject to engine's behaviour (ie may change between runs).
public LunyNativeObjectId NativeObjectId { get; }
Property Value
Remarks
To aid debugging, this ID remains valid after the engine-native object has been destroyed.
Transform
The LunyTransform of this object.
public LunyTransform Transform { get; }
Property Value
Methods
As<T>()
Gets the engine-native object as type T. Returns null for non-matching types.
public T As<T>() where T : class
Returns
- T
Type Parameters
T
Cast<T>()
Gets the engine-native object cast to T. Throws if the type cast is invalid.
public T Cast<T>() where T : class
Returns
- T
Type Parameters
T
Clone()
Creates a new instance of the current object.
public abstract ILunyObject Clone()
Returns
Clone(LunyTransform)
Creates a new instance of the current object and parents it.
public abstract ILunyObject Clone(LunyTransform parent)
Parameters
| Type | Name | Description |
|---|---|---|
parent |
Returns
Destroy()
Marks this object for destruction. If object is enabled, will run its OnDisabled event. Then it run its OnDestroyed event.
public void Destroy()
Remarks
The engine-native object destruction is deferred until the end of the current frame to prevent exceptions.
DestroyNativeObject()
protected abstract void DestroyNativeObject()
~LunyObject()
protected ~LunyObject()
GetNativeObjectEnabled()
protected abstract Boolean GetNativeObjectEnabled()
Returns
- Boolean
GetNativeObjectEnabledInHierarchy()
protected abstract Boolean GetNativeObjectEnabledInHierarchy()
Returns
- Boolean
GetNativeObjectName()
protected abstract String GetNativeObjectName()
Returns
- String
GetNativeTransform()
protected abstract LunyTransform GetNativeTransform()
Returns
Initialize()
public void Initialize()
InvokeOnCollisionEntered(LunyCollision)
public void InvokeOnCollisionEntered(LunyCollision collision)
Parameters
| Type | Name | Description |
|---|---|---|
collision |
InvokeOnCollisionEntered2D(LunyCollision2D)
public void InvokeOnCollisionEntered2D(LunyCollision2D collision)
Parameters
| Type | Name | Description |
|---|---|---|
collision |
InvokeOnCollisionExited(LunyCollision)
public void InvokeOnCollisionExited(LunyCollision collision)
Parameters
| Type | Name | Description |
|---|---|---|
collision |
InvokeOnCollisionExited2D(LunyCollision2D)
public void InvokeOnCollisionExited2D(LunyCollision2D collision)
Parameters
| Type | Name | Description |
|---|---|---|
collision |
InvokeOnCollisionUpdate(LunyCollision)
public void InvokeOnCollisionUpdate(LunyCollision collision)
Parameters
| Type | Name | Description |
|---|---|---|
collision |
InvokeOnCollisionUpdate2D(LunyCollision2D)
public void InvokeOnCollisionUpdate2D(LunyCollision2D collision)
Parameters
| Type | Name | Description |
|---|---|---|
collision |
InvokeOnTriggerEntered(LunyCollider)
public void InvokeOnTriggerEntered(LunyCollider collider)
Parameters
| Type | Name | Description |
|---|---|---|
collider |
InvokeOnTriggerEntered2D(LunyCollider2D)
public void InvokeOnTriggerEntered2D(LunyCollider2D collider)
Parameters
| Type | Name | Description |
|---|---|---|
collider |
InvokeOnTriggerExited(LunyCollider)
public void InvokeOnTriggerExited(LunyCollider collider)
Parameters
| Type | Name | Description |
|---|---|---|
collider |
InvokeOnTriggerExited2D(LunyCollider2D)
public void InvokeOnTriggerExited2D(LunyCollider2D collider)
Parameters
| Type | Name | Description |
|---|---|---|
collider |
InvokeOnTriggerUpdate(LunyCollider)
public void InvokeOnTriggerUpdate(LunyCollider collider)
Parameters
| Type | Name | Description |
|---|---|---|
collider |
InvokeOnTriggerUpdate2D(LunyCollider2D)
public void InvokeOnTriggerUpdate2D(LunyCollider2D collider)
Parameters
| Type | Name | Description |
|---|---|---|
collider |
IsNativeObjectReferenceValid()
protected abstract Boolean IsNativeObjectReferenceValid()
Returns
- Boolean
SetNativeObjectDisabled()
protected abstract void SetNativeObjectDisabled()
SetNativeObjectEnabled()
protected abstract void SetNativeObjectEnabled()
SetNativeObjectInvisible()
protected abstract void SetNativeObjectInvisible()
SetNativeObjectName(String)
protected abstract void SetNativeObjectName(String name)
Parameters
| Type | Name | Description |
|---|---|---|
name |
SetNativeObjectVisible()
protected abstract void SetNativeObjectVisible()
ToString()
public override String ToString()
Returns
- String
TryGetCached(Int64, out ILunyObject)
protected static Boolean TryGetCached(Int64 nativeId, out ILunyObject lunyObject)
Parameters
| Type | Name | Description |
|---|---|---|
nativeId |
||
lunyObject |
Returns
- Boolean
Events
OnCollisionEntered
Runs when the object's collider has "entered" (overlaps) another static or non-kinematic collider.
public event Action<LunyCollision> OnCollisionEntered
Event Type
OnCollisionEntered2D
public event Action<LunyCollision2D> OnCollisionEntered2D
Event Type
OnCollisionExited
Runs when the object's collider stops overlapping/touching another static or non-kinematic collider.
public event Action<LunyCollision> OnCollisionExited
Event Type
OnCollisionExited2D
public event Action<LunyCollision2D> OnCollisionExited2D
Event Type
OnCollisionUpdate
Runs every heartbeat while the collision is ongoing.
public event Action<LunyCollision> OnCollisionUpdate
Event Type
OnCollisionUpdate2D
public event Action<LunyCollision2D> OnCollisionUpdate2D
Event Type
OnCreated
Runs when the object was created or ownership was transferred to LunyEngine. Runs even if the object starts disabled.
public event Action OnCreated
Event Type
Remarks
Engine-native creation events (Unity: Awake, OnEnable / Godot: ctor, _init) will run before OnCreated. OnEnabled will run right after OnCreated if the object starts enabled.
OnDestroyed
Runs when the object was destroyed. Runs even if the object is disabled.
public event Action OnDestroyed
Event Type
Remarks
The object's NativeObject reference is still accessible, it has not been destroyed yet.
OnDisabled
Runs when the object's enabled state changes to "disabled": hidden, not updating, not receiving events, not interacting with other objects.
public event Action OnDisabled
Event Type
OnEnabled
Runs when the object's enabled state changes to "enabled": visible, updating, receiving events, interacting with other objects. Also runs right after OnCreated if the object starts enabled.
public event Action OnEnabled
Event Type
OnReady
Runs once before the object's first frame processing, before OnFrameUpdate and OnHeartbeat. If the object starts disabled, OnReady runs after the object first gets enabled.
public event Action OnReady
Event Type
Remarks
It is not guaranteed that the object will simulate physics in its first active frame. The event order is either: OnReady => OnFrameUpdate (object's first) or: OnReady => OnHeartbeat (object's first) => OnFrameUpdate (object's first)
OnTriggerEntered
Runs when first overlapping a trigger collider.
public event Action<LunyCollider> OnTriggerEntered
Event Type
OnTriggerEntered2D
public event Action<LunyCollider2D> OnTriggerEntered2D
Event Type
OnTriggerExited
Runs when leaving a trigger collider.
public event Action<LunyCollider> OnTriggerExited
Event Type
OnTriggerExited2D
public event Action<LunyCollider2D> OnTriggerExited2D
Event Type
OnTriggerUpdate
Runs while overlapping a trigger collider.
public event Action<LunyCollider> OnTriggerUpdate
Event Type
Remarks
In Unity, to receive this event you have to explicitly enable it: Project Settings: Physics/Settings -> GameObject -> Generate On Trigger Stay Events
OnTriggerUpdate2D
public event Action<LunyCollider2D> OnTriggerUpdate2D