Change frame rate of OnTriggerStay2D

Hey

I just figured out that the OnTriggerStay2D as well as the OnCollisionStay2D functions are called at the same rate as the FixedUpdate function. Is there a way to get them called at the frame rate of the Update function? Or are there other functions that are called onCollision/onTrigger at the rate of Update?
I know I could change a bool in enter/exit and call it in the Update function. I am just curious and I couldn’t find sth anywhere else.

Thanks

All physics messages are called in physics time step.

Yes there is a way to “call” them from Update, but it’s exactly what you’ve described: register stuff happening in OnCollision… then process it in Update.

However you cannot change when physics will call these functions, at least not to my knowledge.
You can change the fixed time interval in Player Project settings though, but this will affect the entire physics engine.

Maybe someone else is more knowledgeable if there is some modern setting I’m not aware of. It’s been a while since I’ve tinkered with physics in more depth.

1 Like

For example, Physics.Simulate is one way to have control over the time step, but this too applies to the whole of your physics. I don’t think there is the best solution, you need to find something that is ok enough for your case.

1 Like

You may try checking out this introductory video that’s relatively fresh. Maybe there is something additional about syncing that I somehow managed to miss out on.

1 Like

In fact, OnTriggerStay (edit: and OnCollisionStay) seems to be very specific in its timing

This is why you haven’t noticed this before. Others are perhaps called asap. Now how exactly all of this works would need some experimentation and deeper analysis before I could tell you anything more. But that’s what I’ve found in the docs.

1 Like

MyPos < Position + (collider bounds extents / 2) and MyPos > Position - (collider bounds extents / 2), you are as good as WithinTrigger, no?