Search Unity

Why Update() is called message in unity?

Discussion in 'Getting Started' started by muhamed_kveshkshaano, May 22, 2021.

  1. muhamed_kveshkshaano

    muhamed_kveshkshaano

    Joined:
    May 10, 2021
    Posts:
    10
    I just surprised why some of called message like awake or start or update in MonoBehaviour?
    Is that mean they send message to something?
     
  2. Because they are called by Unity's core engine from the C++ side. I don't agree with this name.
     
  3. muhamed_kveshkshaano

    muhamed_kveshkshaano

    Joined:
    May 10, 2021
    Posts:
    10
    I still have no ideas why they use the term "message" in this context, would you like explain those method bit in details? I read their documentation it doesn't provide much about it
     
  4. You mean this isn't enough? https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html
    What do you want to know?
     
  5. muhamed_kveshkshaano

    muhamed_kveshkshaano

    Joined:
    May 10, 2021
    Posts:
    10
  6. muhamed_kveshkshaano

    muhamed_kveshkshaano

    Joined:
    May 10, 2021
    Posts:
    10
  7. I'm guessing it comes from the SendMessage service. You can call any method by name without calling it directly, AFAIK it goes through the core as well. Which also means it is extremely slow. It's kind of messaging, but in reality it really isn't. I guess it seemed good enough name back in Unity 1 or 2 (I don't know when was it introduced). Anyway, the important thing is they called message because they are called from the native side to inform your scripts that something is happening. Again, I don't think it's a good name, but it's not bad enough to rename them.
     
  8. muhamed_kveshkshaano

    muhamed_kveshkshaano

    Joined:
    May 10, 2021
    Posts:
    10
    So they are called from core to inform or send message (in unity term) like if left or right is pressed or not to script? Thank you really appreciated
     
  9. Well, you can read on the manual pages the actual purpose of those "messages". In case of Awake for example you get notified that your object is awaking, so you can do whatever you want to initialize your object. Etc. On the MonoBehaviour manual page there is an extensive list of "messages" Unity calls in case something happens to your object.

    No problem, you're welcome!
     
  10. muhamed_kveshkshaano

    muhamed_kveshkshaano

    Joined:
    May 10, 2021
    Posts:
    10
    I think i understand, you meant to say that whatever especially an event occur those method get called and inform to perform the given instructions inside them, am i right?
     
  11. Yes, that's correct.
     
  12. muhamed_kveshkshaano

    muhamed_kveshkshaano

    Joined:
    May 10, 2021
    Posts:
    10
    Thank you really appreciated
     
  13. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,148
    It's important to understand that Unity started life as an Apple-only application and that the developers themselves were originally Apple developers. Apple has had a language for many years known as Objective-C and instead of saying you "call methods" they say you "pass messages".

    https://en.wikipedia.org/wiki/Objective-C#Messages

    That's not to say Apple invented the concept or that the naming came from Objective-C. Message passing exists in multiple languages (eg Go, Rust, Java, etc) and is commonly used to communicate between threads when all other methods (ie monitors, semaphores, etc) are not able to be used.

    https://en.wikipedia.org/wiki/Message_passing
     
    Last edited: May 22, 2021
    JoeStrout likes this.
  14. muhamed_kveshkshaano

    muhamed_kveshkshaano

    Joined:
    May 10, 2021
    Posts:
    10
    Thank you Ryiah, that means those methods list as message in unity documents send some sort of messages?
     
  15. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,148
    No. At runtime Unity makes a list of all the "magic methods" and if it finds one of them it caches that information in a list. Then during runtime it uses the information from the list to call the method.

    https://blog.unity.com/technology/1k-update-calls

    My previous post was simply saying "here are where they likely got the term from" not "this is how it functions".
     
  16. muhamed_kveshkshaano

    muhamed_kveshkshaano

    Joined:
    May 10, 2021
    Posts:
    10
    Thanks Ryiah, as I'm from functional programming mostly JS, python and C i haven't worked any oop design patterns so everything seems bit weird to me, i actually want to know if message methods send the message (in this case some other methods or expressions whatever it's) or something send those message methods as message? Hope you understand my concern