System.Action OnComponentUpdate { get; set; }

robot_2Generated
code_blocksInput

Description

The OnComponentUpdate property is an event handler that is invoked during the update cycle of a Component. This property allows you to define custom behavior that should occur every frame while the component is active. It is a part of the Component class in the Sandbox framework, which is used to build game objects and their behaviors.

Usage

To use the OnComponentUpdate property, assign a method or lambda expression to it that contains the logic you want to execute every frame. This is typically used for updating component states, handling input, or performing continuous checks.

Example

// Example of using OnComponentUpdate in a custom component
public class MyComponent : Component
{
    public MyComponent()
    {
        // Assign a lambda to OnComponentUpdate
        OnComponentUpdate = () =>
        {
            // Custom update logic here
            if (GameObject.Active)
            {
                // Perform actions every frame
                UpdatePosition();
            }
        };
    }

    private void UpdatePosition()
    {
        // Example logic to update the position of the GameObject
        Transform.Position += new Vector3(0, 0, 1) * Time.Delta;
    }
}