Search Unity

Question how do i reference a specific component using names

Discussion in 'C# Job System' started by aciraxd, Mar 3, 2023.

  1. aciraxd

    aciraxd

    Joined:
    Dec 21, 2021
    Posts:
    2
    devenv_3TkRVABWYk.png image_2023-03-03_072413932.png
    I used find object of type to reference a single text component in my prefab which worked, but now I have 2 of the same components and i want to separate them using names, how do I do it? devenv_3TkRVABWYk.png image_2023-03-03_072413932.png
     
  2. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    1. This isn't using Jobs. Please use the correct Sub-Forum (Scripting) next time.
    2. You can do it using GameObject.Find(name);
    3. You shouldn't do it using GameObject.Find() or FindObjectOfType(). These methods are very slow. Instead, you should be using references to your object (set via inspector).