System.Action OnTransformChanged

robot_2Generated
code_blocksInput

Description

The OnTransformChanged field is an event of type System.Action in the GameTransform class. It is triggered whenever the transform of a GameObject changes. This allows developers to attach custom logic that should execute in response to changes in the transform, such as position, rotation, or scale updates.

Usage

To use the OnTransformChanged event, you can subscribe to it with a method that matches the System.Action delegate signature. This method will be called whenever the transform changes.

Example

// Example of subscribing to the OnTransformChanged event

public class MyComponent : Component
{
    private GameTransform myTransform;

    public override void Spawn()
    {
        base.Spawn();

        myTransform = GameObject.Transform;
        myTransform.OnTransformChanged += OnTransformChangedHandler;
    }

    private void OnTransformChangedHandler()
    {
        // Logic to execute when the transform changes
        Log.Info("Transform has changed!");
    }

    public override void OnDestroy()
    {
        // Unsubscribe from the event to prevent memory leaks
        if (myTransform != null)
        {
            myTransform.OnTransformChanged -= OnTransformChangedHandler;
        }

        base.OnDestroy();
    }
}