OnTriggerEnter Question

Why does this code run continuously even though it is not within Update () and is not invoked by Update?

void OnTriggerEnter(Collider other)
{
    print("Player triggered something");
}

I thought that code had to be called from within Update or something similar to be continuously run - but every time I run into an object, the above code prints the ‘triggered’ message to the console - so I know it is continuously running. Then what is the point of putting ProcessRotation(); within Update, if it will just run continuously without it?

Thanks!

Hi,

OnTriggerEnter is part of an event system. It gets called automatically when an event happens (not necessarily each frame!): a collider enters a trigger collider.

In C#, given the programmer followed the official C# naming convention, the On prefix indicates that a method is part of an event system.

Did this clear it up for you?

Thank you, Nina. That makes it very clear!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms