Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document PostTick and PreTick for Simulation #342

Open
Doprez opened this issue Oct 10, 2024 · 2 comments
Open

Document PostTick and PreTick for Simulation #342

Doprez opened this issue Oct 10, 2024 · 2 comments

Comments

@Doprez
Copy link
Contributor

Doprez commented Oct 10, 2024

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:

  • The Bepu physics implementation does not have these events. This will be a Bullet physics doc.
  • C# events kind of suck for performance apparently. Maybe we should give an example on how to make a single event call that can call multiple scripts with some sort of custom processor?
  • Maybe for Bepu we can show how to use the SimulationUpdateComponent which works very similar to Unitys Monobehaviour with the Fixedupdate replaced by SimulationUpdate and AfterSimulationUpdate methods.
@VaclavElias
Copy link
Contributor

Do we need to unsubscribe?

@Doprez
Copy link
Contributor Author

Doprez commented Oct 10, 2024

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

edit: Added to the example above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants