Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
1
Question by GameFishDevelopment · Nov 30, 2017 at 01:52 AM · triggerenemycollison

Player and Enemy collisions: Where should the Trigger/Collision method go, on the enemies or on the player (performance-wise)?

Hi, I am creating a fairly simple 2D Platformer game and I was wondering if each instance of a deadly obstacle (i.e. bomb/mine) should have a script with the OnTriggerEnter2D method checking if what it collides with has the tag "Player" or if my player should have a script with the OnTriggerEnter2D method checking if it collides with something with the tag "Obstacle". Either way, I want to have the obstacle be destroyed and the player to die. Most of the obstacles will be floating (so not colliding with environment) and only need to worry about player collisions. Currently, I have scripts on all the obstacles that check for player collisions and it works but I was wondering if it was better performance-wise if the player did the collision checks, especially when dozens of obstacles are in the scene.

Hopefully what I am asking makes sense. Thank you in advance!

Comment
Add comment · Show 1
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 lPVDl · Nov 30, 2017 at 11:56 AM 0
Share

If collision check is written in the OnCollissionEnter then there is no much performance issues as it will work pretty fine on both sides. Here I guess you need to look at this from the point of logic, as I see it might work something this way "on hit bomb checks if hit object implements interface IDamageReceiver if so, then invoke method TakeDamage(amount)" (feature here is that player code will know nothing about bombs, and that makes your code more flexible).

1 Reply

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

Answer by mafima · Nov 30, 2017 at 01:33 PM

player because there is often only 1 player. 1 collision check is as much more efficient how much enemies you have. if you have 1000 ememies, that check for 1 player every update, than performance will die. collider in general are performance hungry, especcially if you have mesh colliders. i made the experience that replacing 500 mesh colliders with box colliders could double your FPS.

so, if you just want to change PLAYER based variables, yes, by all means go with checking it in the player. hope it helps :) click on "stats" in the Game window on the top right to see the performance.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

88 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

Related Questions

How can I acces the script of an object that I triggered? 1 Answer

Damaging Enemies 1 Answer

Enemy Attraction/Aggro 1 Answer

What’s wrong with my Safe Volume (safe zone) code? 0 Answers

Remove object from List after gameObject was destroyed in between Scene loads 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges