Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 haim96 · Jul 09, 2014 at 01:36 PM · performancegetcomponenteventsendmessage

once again, Sendmessage VS Getcomponent!

i saw a lot of questions and post about this topic, most of the SCREAM don't use sendmessage because it way more slower then events or even getcomponent. as far as i understand events are good to broadcast messages to several receivers at once and getcomponent can send message to specific gameobject.

so for scenario where a bullet need to send damage message to specific gameobject that got hit i first used sendmessage because it was easy and fast to implement. but after i saw these articles and posts i replaced it with getcomponent and to my surprise i got huge performance impact. while asking myself WTF?!.. i roll back to sendmessage.

after a bit more reading i found that getcomponent is fatser when you cache the component you get and then use it, but in my case it useless since the gameobject\bullet destroyed after they get hit and i need to cache the component on every hit.

to my question,what other fast methods can i use with my scenario? ( a reminder, a lot of bullets need to send damage message to an object that got hit)

Comment
Add comment · Show 4
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 gjf · Jul 09, 2014 at 01:41 PM 1
Share

without seeing your code it's a bit of a guess, but ...

why not cache the reference to the object and have the bullet handle damage, etc. before it gets destroyed?

avatar image liszto · Jul 09, 2014 at 01:49 PM 0
Share

Yeah the simple way for me is the same than gif. Cache a ref to your component apply your dmg and co. then destroy it.

avatar image haim96 · Jul 09, 2014 at 01:57 PM 0
Share

i'm pooling the bullets so they not exactly destroyed. also i'm using single bullets type that can make several amounts of damage depend on the shooter. the chain is: shooter setup the bullet properties -> bullet apply damage according his properties.

so, when the same bullet used for both player and several type of NPC, i can't cache them all.

avatar image haim96 · Jul 09, 2014 at 02:10 PM 0
Share

but what is the point of caching component if you only use it once? remember that a bullet can hit several type of objects so every hit it need to cache again the current object that got hit.

1 Reply

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

Answer by whydoidoit · Jul 09, 2014 at 01:52 PM

SendMessage is fine for inflicting damage as long as it isn't happening every frame, the impact is much lower. Without seeing your GetComponent code I can't comment, but it is surprising that this caused a noticeable performance hit which implies it might have been coded oddly.

Comment
Add comment · Show 2 · 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 haim96 · Jul 09, 2014 at 02:07 PM 0
Share

i don't have a profiler but i could see the impact when the render time jump from 0.2ms to 0.4-0.6ms. for the code, i'm not near my home computer but i will post it later...

avatar image haim96 · Jul 10, 2014 at 12:33 PM 0
Share

i decided to stay with sendmessage since i don't use it every frame and the performance are good. thanks for your answer!

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

23 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

Related Questions

SendMessage or GetComponent 1 Answer

Looping through materials on a mesh with foreach() in Start() is causing lasting FPS drop? 1 Answer

Send Message? 1 Answer

Performance of C# Events on iPhone/Android 1 Answer

Sendmessage/GetComponent (read variable only) help 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