stride3d / stride-docs

This repository hosts the source code for the Stride documentation. Contributors can follow the build instructions provided to run the website locally.
https://doc.stride3d.net/
MIT License
31 stars 65 forks source link

Document `PostTick` and `PreTick` for Simulation #342

Open Doprez opened 1 month ago

Doprez commented 1 month ago

We should add a section to the Physics manual to show how to subscribe to the physics tick events in order to mimic what people are used to for FixedUpdate.

Example:

using Stride.Engine;
using Stride.Physics;

public class FixedUpdate : StartupScript
{
    public override void Start()
    {
        var sim = this.GetSimulation();
        sim.PreTick += Sim_PreTick;
        sim.PostTick += Sim_PostTick;
    }

    private void Sim_PreTick(Simulation sender, float tick)
    {
        // Run before the Simulation is updated
    }

    private void Sim_PostTick(Simulation sender, float tick)
    {
        // Run after the Simulation is updated
    }

    public override void Cancel()
    {
        var sim = this.GetSimulation();
        sim.PreTick -= Sim_PreTick;
        sim.PostTick -= Sim_PostTick;
    }
}

This should be a pretty simple manual page I think but we should also add it to the Stride for Unity® developers somewhere that would mention FixedUpdate from Unity.

more things to think about:

VaclavElias commented 1 month ago

Do we need to unsubscribe?

Doprez commented 1 month ago

Yes, absolutely worth mentioning maybe in the Cancel method that is overridable.

edit: Added to the example above.