Initialization script when game starts

Hello! I’m having trouble with something.

I want to add some components to multiple game objects before the game starts to run. I’m doing this via script because I need to add the same components to a lot of objects (+600), so doing it on the editor is very time consuming. The problem is that if I do it in the start() function, the script is not completely executed when the game starts, and as result, it doesn’t work properly.

Is there a way I could force the game to wait until the script has been completely executed? Or maybe something to add the components quickly from the editor?

Thank you !


You have mutliple solutions.

First, and the best way is a correct use of the 3 starting methods , wich are exectued in this order

Awake() - OnEnable() - Start()

Another way is to assign this variables in the first Update, with a if sentence with bool variable to know if already assigned.

The last way is, as you say, by editor, 1 by 1, wich is so booorgin :smiley:


okay thank you for your answer… but can you please be a bit more specific? the only way i figured out to make it is using a for loop, and i want it to finish that loop before game starts… have you got any idea on how to achieve that?

If you need to place the same component on 600+ objects, could you not select all of them in the hierarchy then just add the components? For example, I have destructible objects with 100+ cubes that I need to place rigidbodies and box colliders on. I just pick the first one, scroll down to the bottom of the hierarchy, then shift+click the last one, then I go about adding those two components. If I need to modify values, I do the same, select all of them, then change the values.