Search Unity

i accidentally wiped most of script listed in Script Execution Order settings. is it dangerous?

Discussion in 'Editor & General Support' started by SaintFlorida, May 22, 2023.

  1. SaintFlorida

    SaintFlorida

    Joined:
    Mar 22, 2023
    Posts:
    1
    so i think i made a huge mistake because i mess around with unity setting, i clicked funny button called reset in Script Execution Order settings window. there was many scrip on that list, after i reset it, only these are left .i haven't encounter any error as of now should i create new project? because i cant really remember what scripts that was wiped from the list (i use a lot of asset=many script) (edited)
     

    Attached Files:

  2. tsibiski

    tsibiski

    Joined:
    Jul 11, 2016
    Posts:
    604
    Script execution order dictates the order that monobehaviours execute. Consider a situation where you made some master script, ScriptA, where ScriptB, ScriptC, etc all reference a value (MyImportantComponent) set in the Start() method of ScriptA. If ScriptB or ScriptC were to run their Start() methods first, and access the MyImportantComponent variable, it would be null - and you'd get null reference errors.

    Until now, you've always had ScriptA execute first, so you've never had an error before. But you start adding new Monobehaviours to the project, and suddenly ScriptC is the first script to have its Start() method run - now you have null reference errors. But if you put ScriptA in the script execution order in the editor like shown in your picture, it will always run first again - as long as you don't add ScriptB or ScriptC to the script execution order - while giving them a higher weight.

    Still, you should use the script execution order feature sparingly, because it is not scalable and gets very messy. Instead, you should leverage Awake() methods on critical scripts that must run first - and then use Start() methods for the other scripts that reference a value set in the important script's Awake() method. This works because Awake() methods in all monobehaviours always run before any monobeaviour's Start() methods.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    ^ ^ ^ This. Try not to rely on it. Call your scripts from each other if order is absolutely critical.

    All that said, you should use source control so you can revert mistakes like this with one click.

    PROPERLY CONFIGURING AND USING ENTERPRISE SOURCE CONTROL

    I'm sorry you've had this issue. Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.

    Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

    You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

    As far as configuring Unity to play nice with git, keep this in mind:

    https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

    I usually make a separate repository for each game, but I have some repositories with a bunch of smaller test games.

    Here is how I use git in one of my games, Jetpack Kurt:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

    Using fine-grained source control as you work to refine your engineering:

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

    Setting up an appropriate .gitignore file for Unity3D:

    https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

    Generally the ONLY folders you should ever source control are:

    Assets/
    ProjectSettings/
    Packages/

    NEVER source control Library/ or Temp/ or Logs/
    NEVER source control anything from Visual Studio (.vs, .csproj, none of that noise)

    Setting git up with Unity (includes above .gitignore concepts):

    https://thoughtbot.com/blog/how-to-git-with-unity

    It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place. Digital storage is so unbelievably cheap today that you can buy gigabytes of flash drive storage for about the price of a cup of coffee. It's simply ridiculous not to back up.

    If you plan on joining the software industry, you will be required and expected to know how to use source control.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards