Table of Contents

Interface ILunyObject

Namespace
Luny.Engine.Bridge
Assembly
Luny.dll

See implementation: LunyObject

public interface ILunyObject

Properties

IsEnabled

Whether the engine object is processing and visible. Matches the "Active" state of Unity.

bool IsEnabled { get; set; }

Property Value

bool

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.

bool IsEnabledInHierarchy { get; }

Property Value

bool

IsNativeObjectValid

Is true when Destroy() was called on the NativeObject and it was set to null.

bool IsNativeObjectValid { get; }

Property Value

bool

IsValid

Whether the object and its native representation are valid (not null, not destroyed).

bool IsValid { get; }

Property Value

bool

IsVisible

Whether the object is visible (will render).

bool IsVisible { get; set; }

Property Value

bool

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!

LunyObjectId LunyObjectId { get; }

Property Value

LunyObjectId

Name

The name of the object in the scene hierarchy.

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.

object NativeObject { get; }

Property Value

object

NativeObjectId

Engine-native object's unique, immutable identifier. Subject to engine's behaviour (ie may change between runs).

LunyNativeObjectId NativeObjectId { get; }

Property Value

LunyNativeObjectId

Remarks

To aid debugging, this ID remains valid after the engine-native object has been destroyed.

Transform

The LunyTransform of this object.

LunyTransform Transform { get; }

Property Value

LunyTransform

Methods

As<T>()

Gets the engine-native object as type T. Returns null for non-matching types.

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.

T Cast<T>() where T : class

Returns

T

Type Parameters

T

Clone()

Creates a new instance of the current object.

ILunyObject Clone()

Returns

ILunyObject

Clone(LunyTransform)

Creates a new instance of the current object and parents it.

ILunyObject Clone(LunyTransform parent)

Parameters

parent LunyTransform

Returns

ILunyObject

Destroy()

Marks this object for destruction. If object is enabled, will run its OnDisabled event. Then it run its OnDestroyed event.

void Destroy()

Remarks

The engine-native object destruction is deferred until the end of the current frame to prevent exceptions.

Events

OnCollisionEntered

Runs when the object's collider has "entered" (overlaps) another static or non-kinematic collider.

event Action<LunyCollision> OnCollisionEntered

Event Type

Action<LunyCollision>

OnCollisionEntered2D

event Action<LunyCollision2D> OnCollisionEntered2D

Event Type

Action<LunyCollision2D>

OnCollisionExited

Runs when the object's collider stops overlapping/touching another static or non-kinematic collider.

event Action<LunyCollision> OnCollisionExited

Event Type

Action<LunyCollision>

OnCollisionExited2D

event Action<LunyCollision2D> OnCollisionExited2D

Event Type

Action<LunyCollision2D>

OnCollisionUpdate

Runs every heartbeat while the collision is ongoing.

event Action<LunyCollision> OnCollisionUpdate

Event Type

Action<LunyCollision>

OnCollisionUpdate2D

event Action<LunyCollision2D> OnCollisionUpdate2D

Event Type

Action<LunyCollision2D>

OnCreated

Runs when the object was created or ownership was transferred to LunyEngine. Runs even if the object starts disabled.

event Action OnCreated

Event Type

Action

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.

event Action OnDestroyed

Event Type

Action

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.

event Action OnDisabled

Event Type

Action

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.

event Action OnEnabled

Event Type

Action

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.

event Action OnReady

Event Type

Action

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.

event Action<LunyCollider> OnTriggerEntered

Event Type

Action<LunyCollider>

OnTriggerEntered2D

event Action<LunyCollider2D> OnTriggerEntered2D

Event Type

Action<LunyCollider2D>

OnTriggerExited

Runs when leaving a trigger collider.

event Action<LunyCollider> OnTriggerExited

Event Type

Action<LunyCollider>

OnTriggerExited2D

event Action<LunyCollider2D> OnTriggerExited2D

Event Type

Action<LunyCollider2D>

OnTriggerUpdate

Runs while overlapping a trigger collider.

event Action<LunyCollider> OnTriggerUpdate

Event Type

Action<LunyCollider>

Remarks

In Unity, to receive this event you have to explicitly enable it: Project Settings: Physics/Settings -> GameObject -> Generate On Trigger Stay Events

OnTriggerUpdate2D

event Action<LunyCollider2D> OnTriggerUpdate2D

Event Type

Action<LunyCollider2D>