• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by toishaanpatel · Jul 10, 2020 at 03:28 PM · triggersperformance optimizationracing gamepositions

Is too many trigger colliders and function calls very bad for game performance?

I am making a karting game and for the positioning system, I am using about 400 trigger colliders placed very close to each other around the track, and everytime the player or opponent enters one of them, a value increments in their script. Then every 0.2 seconds, a function call happens in the race manager script, which sorts a LIST (not array) of references (scripts) to each player/opponent, according to that value being incremented in the race. The index+1 of every player in the list represents their position. The positioning system works fine, and I am testing it with 3 players currently. I did not notice any frame rate drops when testing the game, but I was wondering if this is a bad idea and if I should go for another solution. Earlier, I tried the three way sort method where it first tries to organize players by lap they are on, then by the value I described, and then by the distance to the next checkpoint if two players are on the same upcoming checkpoint. I avoided this because I heard that vector3.distance can be expensive if called too much.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Magso · Jul 10, 2020 at 04:30 PM

"400 trigger colliders placed very close to each other around the track, and everytime the player or opponent enters one of them, a value increments in their script."

I also used to do this and yes the performance will suffer. You're better off using only a few waypoints and using the Vector3.Distance method, multiply the returned number by the waypoint number and sort the array lowest to highest.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image toishaanpatel · Jul 10, 2020 at 05:42 PM 0
Share

Oh, ok. Is the method call to the OnTriggerEnter very heavy? If so, then I will change the method I use for positions

avatar image toishaanpatel toishaanpatel · Jul 10, 2020 at 05:45 PM 0
Share

Because I was having issues with the vector3.distance comparison thing. I just used this method since it is an easy way to do it. However, I will revisit the vector3.distance method and try to make it work.

avatar image Magso toishaanpatel · Jul 10, 2020 at 05:59 PM 0
Share

Vector3.Distance isn't heavy, it's returning a length of a vector as a float as opposed to OnTriggerEnter which is using physics to return a collider type.

Edit: technically OnTriggerEnter returns void, the collider is the parameter given by the physics engine.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

134 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why Trigger colliders costs more than non trigger ones? 0 Answers

Make an object a trigger? 1 Answer

Optimize performance of simple survival game 1 Answer

How to make cheap terrain for ocean floor? 0 Answers

Massive framerate drops because of rendering? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges