when i shoud use “void Main” the function be call after awake and before start
it’s really interestion, the Main like C# Main function , notice the color between “Main” and “Start”
the order is not based on the order you write them in the class, but rather the order unity calls them.
With that said, I’m unaware of a message named ‘Main’ in Unity. In what way are you calling ‘Main’?
Ok, I just tested, and if you have a ‘Main’ method in a MonoBehaviour it is called. And it’s sequenced between Awake and Start.
Not sure what it’s for, it appears to be undocumented…
Anyone know what it’s for, it should be avoided (since it is undocumented). Never really called a method Main so I never ran into this before.
I will repeat though… ordering of your functions in your class does NOT control the order in which Unity sends those messages. The order is what Unity defined it as. And Awake occurs before Start.
The reason Awake and Start are coloured differently is because the IDE is aware of the Unity messages like Awake and Start and colours them for you appropriately to designate their significance. Since ‘Main’ is undocumented, it’s not considered a message name, and therefore isn’t coloured by the IDE.
Whoa yeah, definitely listen to @lordofduct and avoid this function. While that is NEAT and all, just use either Awake() or Start(), as appropriate. Main() is an undocumented magic function, and it could in the future NOT get called, or get called multiple times, or get called only on certain platforms and not others. AVOID! FEAR! FIRE! FOES! ![]()
And lets not forget that calling a method Main can also do other nasty things if you ever pull parts of your project back to regular C# land.
I would strongly advise never to have a method called Main in a Unity project.
