- Home /
Order execution of the same script puzzle?
Hello there!
So, it looks like I have one script which is attached to different objects.
How can I set order execution of this script? What a puzzler!
I tried to use mono manager but of course, it only helps with order of different scripts.
Answer by Bunny83 · Dec 30, 2012 at 12:06 PM
You can't. Unity has internal lists which are used when you add or remove objects at runtime those lists will change. You can't rely on a certain execution order.
The easiest way is to use your own function. For example:
// Follow.cs
public void ExecuteStuff()
{
// ...
}
// FollowManager.cs
public Follow[] followScripts;
void Update()
{
foreach(var script in followScripts)
script.ExecuteStuff();
}
You need one FollowManager script and add a reference to the followScripts array in the inspector in the order you like.
Bal asks: "thank you for quick replay. to which object should i attach Follow$$anonymous$$anager? to object1 or object2? "
I suggest, make a NEW object (call it something like "HandyControllerThanksToBunny" ) and attach a new script Follow.cs to that object.
I travelled forwards in time, and checked that thank goodness, Bunny agrees with this suggestion.
Exactly ;) Just add another object and attach the manager script.