Answer the question
In order to leave comments, you need to log in
Changing the creation order of objects in Unity?
The problem is this: let's say we have 2 objects, one of them has such a script attached to it
public class GameController : MonoBehaviour
{
public static GameController Instance;
public Transform SomeTrasform; // Задается в Editor'e
private void Start()
{
Instance = this;
}
}
public class SomeClass : MonoBehaviour
{
private void Start()
{
Transform someTransform = GameController.Instance.SomeTransform;
}
}
Answer the question
In order to leave comments, you need to log in
If you need to manage the sequence of starts, then it's time to change the architecture. Your GameController must either instantiate objects with SomeClass, or initialize them, or whatever. Read about singletons at the link below.
www.gameprogrammingpatterns.com/singleton.html
1. You can use Awake() instead of Start() for the first object
private void Awake()
{
Instance = this;
}
public class SomeClass : MonoBehaviour
{
private bool _inited = false;
private void MyStart()
{
Transform someTransform = GameController.Instance.SomeTransform;
}
private void Update()
{
if (!_inited)
{
MyStart();
_inited = true;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question