Search Unity

Is heavy to use a manager file to call all objects?

Discussion in 'Scripting' started by p627, Oct 10, 2015.

  1. p627

    p627

    Joined:
    Apr 12, 2014
    Posts:
    23
    Hello, Is heavy to use a manager file to call all GameObjects and Transforms and than to use manager = GetComponent<manager>() in Awake() to the files that i want to use the GO or Transforms?

    void Awake()
    {
    manager = GetComponent<manager>()
    }

    void Update() // Most will used in UPDATE function
    {
    // an example about how the calls wil look,

    manager.healthbar.transform.position;
    manager.turret.transform.position;
    manager.BoxCollider.enable;
    }
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Performance wise it's not a big deal. Following references is one of the cheapest operations you can do.

    It's worth considering it from a code maintainability point of view though. With this setup you have made all of your classes dependent on the manager script and dependent on whatever classes the manager script exposes.

    It's not too bad if you are only accessing GameObject and Transform this way. It might even be beneficial it if you find yourself in need of a misdirection layer. But I'm always wary of something that adds in extra dependency, just on principle.
     
  3. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    It will take one extra GetComponent :p