Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

General Scripting Etiquette

Discussion in 'Scripting' started by MahaloAloha, Jan 10, 2021.

  1. MahaloAloha

    MahaloAloha

    Joined:
    Jan 9, 2021
    Posts:
    31
    Aloha.

    Since I have no technical issues with C# itself, I had a more general question with how Unity handles multiple layers of scripting.

    By force of habit I have multiple layers of scripts but tend to encompass all aspects about an entity - object or child - into one consolidated file
    I do this with the intention of hot-swapping elements within the lower, child processes in order for dynamic feedback into the parent script without altering the behavior of other children or the parent object as a whole.

    My background is in coding features for various non-Unity projects and this is my usual methodology. (Minimum Files with orderly calls to other scripts. Less Confetti and Less Spaghetti)

    Question of the Day:
    Will this come back to bite me in the ass down the road? Does Unity handle this and I'm simply being redundant? Will this effect performance and the ultimate file-size?

    Thanks for any input you have on the matter. I'm picky for optimization but if it's not that huge of a deal I may relax just a bit and just work script by script with the knowledge that Unity will handle any compression/file consolidation in the post- processing.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
  3. MahaloAloha

    MahaloAloha

    Joined:
    Jan 9, 2021
    Posts:
    31
    Thanks, mate. Having the Order of Execution under UNITY will definitely help.

    In fact, it answers more questions I had than I initially asked.

    Kudos, Muchachos.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    Awesome. The pattern I use is to try set stuff up so I don't care about order between scripts, and when I do want it, I always explicitly call one script from the other using a public method and GetComponent to get the other script.

    I don't like using script execution order because it is out of sight of the code, and if you copy a couple of files from one project to the other in the future, you won't (necessarily) be copying the execution order and then you'll have mysterious errors.
     
    mezzaninex and Bunny83 like this.