Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SendMessage is a trap

Discussion in 'Scripting' started by TurnBased, Sep 8, 2016.

Thread Status:
Not open for further replies.
  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    I'm not blaming anyone. I'm saying that SendMessage should not be used by sane people anymore.

    You're not the one landed here, check the view count of this thread.
    So its an information investment for the future generations.

    Unfortunately, it does in that case.

    Because this one exists:
    Code (CSharp):
    1.  UnityPlayer.UnitySendMessage("ObjectName", "MethodName", "parameter");
    That's an API for the android that does the same exact thing as Find + SendMessage.
    Both Find and SendMessage are evil. Combined? Makes even more troublesome issues to arise when you do not expect that.

    Unfortunately, these jewels aren't always reflected in the manual.
    So in the end it just doesn't work sometimes because of the name missmatch, and its completely unknown why.

    God bless development mode. At least it has this message if something went wrong:
     
    Last edited: Jun 18, 2019
    SparrowGS likes this.
  2. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,992
    Tags are another thing that all pre-Unity game designers knew about and used. As in: an actual guy I know: "boss, this Unity3D you wanted me to check out - it has scripts, sendMessage, lookAt and tags; so we could use it". They're clunky, but are easy to understand and work fine for most games.

    Saying unity should get rid of X or Y since it's slow and teaches bad habits is like saying cars shouldn't have automatic transmissions, since they're less efficient and make it more difficult to learn how a drive shaft works. Most game designers aren't working on games where speed is an issue - puzzle games, crafters, hidden objects, stories, most collectable hero games ... . And they never want to learn intermediate-level programming, and if they did, it would be something more like python. None of the reasons apply to them.

    But I think I'm in agreement, and have long been, with Verglex about " information investment for the future generations". SendMessage should say that if you're learning C#, skip it. Commands, write-ups and such should indicate who they're meant for - get-the-job-done practical game designers, or "I'm using Unity to learn Enterprise C#", or in-between. At the very least, when someone is about to write "your example sucks since you didn't cache the transform" they can see the "fast-and-simple code" heading and stop themselves.
     
    LukeNukem44 likes this.
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,753
    @LukeNukem44 You may don't like others views and you don't have to agree. Is your choice. Bu please don't offend forum users. This wrong forum for that. Digest your salty cheese burger and please come back, when you calm down.
     
    IvanC314 likes this.
  4. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Tags can die, if a designer can use tags he can learn to slap components on game objects too, which is more robust way of tagging objects for certain behaviour
     
    Last edited: Jun 22, 2019
    Ryiah and lordofduct like this.
  5. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,042
    Closed because people cannot act like adults. Warnings issued. Behave like civilized adults in the future or lose your ability to participate. Off topic discussion trimmed..
     
    Ryiah and Antypodish like this.
Thread Status:
Not open for further replies.