Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Generation on load every time?

Discussion in 'Getting Started' started by 82ross, Dec 9, 2015.

  1. 82ross

    82ross

    Joined:
    Dec 9, 2015
    Posts:
    4
    Hello,

    Forgive me if this is a daft question or if its answered elsewhere.

    I have written a script to generate a number of elements, a primitive with some text and models associated with it.

    I used script to save me manually building 100+ unique objects and on load they generate okay. They dont change once generated.

    My question is, should I leave this to generate via script every time or should I somehow export them once generated into the editor so i can remove the generating script from runtime?

    Is there a performance benefit for either way?

    PS a quick thanks to all members of this forum. As a beginner I have cobbled together a little bit of knowledge from bits of support people have given to others in the past.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,206
    I would absolutely keep the procedural generation (which is what we call what you're doing) in place unless you have some reason to do otherwise — for example, if it's so slow that the user notices the load time.

    But unless you're doing some very heavy math, I bet 100+ objects snap into existence without any noticeable effect on level load time. So, keep it. It will make it much easier to manage when you decide you need to change something on all the objects, or space them out a bit differently, or whatever.
     
    Martin_H likes this.
  3. 82ross

    82ross

    Joined:
    Dec 9, 2015
    Posts:
    4
    Much appreciated, its only the known elements (as in protons, neutrons, electrons.)
    Im just moving from Unity4 to 5 so thought its as good a time as any to make such a change. There is next to no delay on load.

    Thank you for you advice. Now to iron out all the little bugs the transition has introduced!
     
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    FWIW: You can procedurally generate items in EDIT TIME by using editor scripts.

    If you want to create something procedurally, but have that exact creation persistent and not take any runtime resources to calculate it, then look into editor scripting, and create an editor script that creates your objects in edit time in the scene.
     
    JoeStrout and Martin_H like this.
  5. 82ross

    82ross

    Joined:
    Dec 9, 2015
    Posts:
    4
    Just got around to looking at this Adam. This was exactly what I was looking for but never came across prior to this.
    Thank you.
     
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Editor scripts are a very important but completely different world to run time scripting. They are definitely worth looking at, and can help save you a whole load of work and trouble when you get into a big project. Editor scripting can help you automate processes while you are creating your game, and can do things like improve the detail of the inspector with custom drawers and other important attributes.
     
unityunity