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
2
Question by hardRock · Jun 29, 2012 at 05:29 AM · optimizationeventsendmessageframework

How effective are events in unity3d?

Hi i am planning to write a framework for unity3d to make 2d game dev. simple and easy. i want to know which one of it is faster, "C# events" or "Unity's SendMessage". I know both are slow only but if i have to choose one which one should i prefer, taking into account, speed of execution, build size, code maintenance, ease to work with and other stuffs. please help me, I dont want to go wrong with the core itslef. And also suggest me any other event based method to do so, if both of these are not good.

Comment
Add comment · Show 2
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 asafsitner · Jun 29, 2012 at 07:09 AM 0
Share

Considering build size, code maintenance and ease to work with I'd suggest the built in Send$$anonymous$$essage.

I haven't run tests on either so I can't comment on speed of execution, but I don't believe it will be your bottleneck (I fear the Garbage Collector and the Dreaded $$anonymous$$ysterious Overhead more than anything else).

avatar image kamran-bigdely · Aug 18, 2016 at 08:55 PM 0
Share

On side note, you can use UnityEvent. For comparision between C# event and UnityEvents see this article.

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by whydoidoit · Jun 29, 2012 at 08:26 AM

C# events are not at all slow. Delegates known ahead of time are very fast indeed (faster than doing a transform.position in your code). C# events have a number of limitations - they keep the objects alive if you are not careful so you have to make sure you remove your handlers. SendMessage is fairly slow and doesn't give you much flexibility around parameters - you certainly won't have events that can cancel or modify an operation if you use them. It depends what you need.

Tips:

  • Don't use anonymous methods to handle events (they are hard to remove and can create closures that hold lots of things open)

  • for performance cache things like transform in local variables (don't believe doing transform. In a script is the same as accessing a variable)

  • remove handlers in OnDisable or OnDestroy

Comment
Add comment · Show 1 · 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 flamy · Jun 29, 2012 at 09:06 AM 1
Share

adding to this, if you can get any prime31 plugin's you could see how good c# events are handled, and ofc everything has its own limitations.

avatar image
1

Answer by fafase · Jun 29, 2012 at 07:58 AM

http://answers.unity3d.com/questions/243876/efficiency-of-sendmessage.html

This thread has a quick benchmark that could answer your question.

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

8 People are following this question.

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

Related Questions

How to add a custom message to the existing monobehaviour messages? 0 Answers

notify just gameobjects close to specific position 1 Answer

once again, Sendmessage VS Getcomponent! 1 Answer

Sending and Receiving Messages globally with BroadcastMessage / SendMessage 4 Answers

Can someone explain SendMessage to me? 3 Answers


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