playMaker

Author Topic: Send Message vs Send Event  (Read 6934 times)

ergin

  • Junior Playmaker
  • **
  • Posts: 86
Send Message vs Send Event
« on: June 09, 2016, 11:38:26 AM »
I wonder which one would be more efficient:

Let's assume we have 50 game objects and we need to disable them(set active false) or UI set text

Which would cost less cpu:

1- SendMessage / Set Property them set active false or UI set text
2- Every object would have an FSM on them and we use "send event" action to trigger the action.

or is there a more efficient way.

Thanks.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Send Message vs Send Event
« Reply #1 on: June 09, 2016, 06:59:52 PM »
Hi,
I am not sure which one is best but you maybe you could test this with the 'profiler'

disable, then next frame, then enable and loop back to disable.

ergin

  • Junior Playmaker
  • **
  • Posts: 86
Re: Send Message vs Send Event
« Reply #2 on: June 09, 2016, 08:47:11 PM »
Thanks djaydino,

I actually read at http://wiki.unity3d.com/ on "General Performance Tips" that :
"SendMessage() is at least 100 times slower than calling a function directly, and this number increases as more scripts and functions are available on the object. If you can find the script you need ahead of time, do so and then call the function directly."

Thats why I wanted to ask pros here how they do such things. I used a lot of Sendmessages in my project and I'm about to change it, and wondering if there is a better solution or is send event the best alternative...

Thanks again.

http://wiki.unity3d.com/index.php?title=General_Performance_Tips

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: Send Message vs Send Event
« Reply #3 on: June 10, 2016, 02:37:06 AM »
Interesting info..

How do we call a function directly in playmaker?

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Send Message vs Send Event
« Reply #4 on: June 10, 2016, 03:15:12 AM »
As far as I know. (although I must say Im struggling to get a function in a script to work RIGHT NOW) the way is to DRAG the component containing the script with the function you wish to use to the PlayMaker window. Before it drops it will give you the option of Set or Get. If you want to use the output of a function in a script IN PLAY MAKER you hit Get... if you want to change the value in the function, you hit SET. Then you have an action that contains a drop-down menu. search the drop down for the function you want to use and select that. The action with then present you with editable elements that you can now control in PlayMaker.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Send Message vs Send Event
« Reply #5 on: June 10, 2016, 03:19:11 AM »
Hi,

 Indeed sending PlayMaker Event will be a lot more efficient then sending Unity Messages.
 
AS for using Invoke, this would require hard data, but reflection is generally not a good idea especially on mobile.

 The ultimate way is to create a dedicated Custom action accessing directly without reflection, the class and methods/properties you want to call, set/get. That's the best way.

As for "Managed" over "Object oriented" approaches, it's balance between clean code/fsm and efficiciency. Always prefer Object oriented first, then if you find a bottle neck, then you can go for a managed way ( one fsm controlling several properties on other gameobjects).

Always develop the feature you want exactly so that it works, and then optimize if you find a problem as you profile, Don't optimize first, you'll corner yourself and end up refactoring more than when you need to refactor for optimization reasons.

The worse you can do here is instantiating objects and components, so mayke sure that you use a pooling system if you do, and else make sure you do that either on start of the game or time it with menus and pauses in games to avoid hickups.

 Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Send Message vs Send Event
« Reply #6 on: June 10, 2016, 03:21:39 AM »
As far as I know. (although I must say Im struggling to get a function in a script to work RIGHT NOW) the way is to DRAG the component containing the script with the function you wish to use to the PlayMaker window. Before it drops it will give you the option of Set or Get. If you want to use the output of a function in a script IN PLAY MAKER you hit Get... if you want to change the value in the function, you hit SET. Then you have an action that contains a drop-down menu. search the drop down for the function you want to use and select that. The action with then present you with editable elements that you can now control in PlayMaker.

Hi,

 That's a very  productive way to do this, but not necessarly the most effective technically speaking because you'll be relying on Reflection which isn't ideal, as I said in the post ( as you where writing yours :)  the most efficient way is to "hardcode" it into a custom action, that way, no reflection, it's a direct access.

Note: Always cache the script/component you access in the custom action, avoid using "getComponent<>()" on every update, this is also important for efficiency.

Bye,

 Jean

ergin

  • Junior Playmaker
  • **
  • Posts: 86
Re: Send Message vs Send Event
« Reply #7 on: June 10, 2016, 07:29:03 AM »
Thanks markfrancombe and dudebxl for the tips,
Thanks jeanfabre for the infos I really needed...