Common Scripting Pitfalls

From Unify Community Wiki
Revision as of 01:37, 28 April 2006 by Aarku (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

SendMessage and BroadcastMessage

What is the difference between these two lines of code?

  1. <csharp>someGameObject.SendMessage("SomeCoolFunction", SendMessageOptions.DontRequireReceiver);</csharp>
  2. <csharp>someGameObject.SendMessage("SomeCoolFunction", null, SendMessageOptions.DontRequireReceiver);</csharp>

In the first line of code, we are sending somegameobject the message "SomeCoolFunction" along with the object SendMessageOptions.DontRequireReceiver. That is most likely not what we want!

To correct this, we basically add the null argument in the middle. Now we are not sending SomeCoolFunction any object, but we are not requiring the message to have a receiver.

This is a common pitfall when writing code that is messaging objects that may not have a receiver.

Personal tools