Quick Tip: Script Execution Order (Unity Tutorial)

preview_player
Показать описание
Sometimes you need one script to execute before another one. Use the Script Execution Order window.

If you have any questions post them in the comments and I'll do my best to answer them.

See you next time!

#unity3d #tutorial #unity2d

--------------------------------------------------------------------

Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.

I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.

--------------------------------------------------------------------

Рекомендации по теме
Комментарии
Автор

🌐 Have you found the videos Helpful and Valuable?

CodeMonkeyUnity
Автор

Another tip: there's a way to do the same thing only from the code!
Add the [DefaultExecutionOrder] attribute to your class. Simple as that.
The attribute takes an int, which works the same as the list shown in the video (begin > negative > zero > positive > end).

For some reason, the attribute is not shown in the online documentation, but it is used in the Nav Mesh components, among others.
Keep in mind that if you change the execution order with this attribute, it will not be shown in the editor's execution order list.

GiraPrimal
Автор

So, you're telling me that hours or IEnumerating my inits were spent so I could be shocked by this video??! FML!

tbarcello
Автор

Not only was a finding a lesson for Script Execution Order, but you also solved a problem I'm struggling with! Thanks.

misterrhombus
Автор

Awesome! I wasted so much time with that error... I had no clue that you can rearrange the execution order, so I was simply trying to use singleton as few times as possible. Passing objects via properties guarantees that such error will never happen. However, your solution is awesome, thanks!

rickloyd
Автор

thank you so much! it helped a lot, I love your tutorials and games!

Vueltero
Автор

Thank you for the concise videos, it makes it easy to quickly reference.

personalgamedevyt
Автор

Thank you. That was a very useful tip.

simonsovic
Автор

OMG and I had to use a one-frame coroutine for this

userlink-
Автор

^.^ with helpful videos like this coming out so frequently my game will be amazing.

Question: will you be making tutorials on making multiplayer?

themirlabs
Автор

Thank you, so much. I couldn't work out why my script wasn't subscribing to an event

envexenveritas
Автор

But in this particular example you have, isn't it like 100, 000 times more correct to do some of that in the Start method? Shouldn't you always only call external stuff in the Start method and not in Awake?

DrHeinzDoofenshmirtz
Автор

[update: fair enough you address this point in another comment. The Execution Order is useful, but it’s not the best example scenario]

In GameHander why not move the SetMoneyDisplay call into the Start method . Ideally you only really want to use Awake to set things on the same object the script is on, not to talk to other objects that are still processing their Awake cycles. Sure Execution Order can solve it here but it seems unnecessary. Also you can end up having to change the Execution order of several scripts once you try scale this out, instead of just using the correct approach in the first place, and not have to worry about it

joep
Автор

Hey code monkey could you make a tutorial to organize your code or how to use MVC in the classes? :)

mehmedcavas
Автор

Codemonkey can u make a tramsformation like maybe we can say that im a vilager and if i press maybe q or a button on my keyboard i transform to a monster so im stronger or something if posible and its the player that transforms not a enemy or something if its posible❤️

tilexusit
Автор

Just found this--it's like a magic fix for so many annoying errors! With the ability to change execution order, is there ever a reason to use Start() instead of Awake()?

JediMediator
Автор

How does this work with DOTS? systems run before mono? Thanks

shotoutgames
Автор

Hello When I add script below default time the location of gameobjects changed. What could be the reason. Can anyone help?

bhanusri
Автор

There's attributes for this now, so you can write it in the script instead

Aeroxima
Автор

buf if the script will be the same and the objects will be different ?

kagankarakaptan