Search Unity

Get parameters on prefab that isn't instantiate

Discussion in 'Scripting' started by Honikou, Aug 29, 2015.

  1. Honikou

    Honikou

    Joined:
    Feb 18, 2013
    Posts:
    92
    Hi,

    I would like to get parameters on prefab that isn't instantiate.

    For example, the prefab A, have a script "Script", with the value "Hello".

    How to get the value Hello without instantiate the prefab ?

    Thank you
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You can reference the prefab just like a scene object. Have a public variable, assign the prefab to it and use getComponent<YourScript>().
     
  3. Honikou

    Honikou

    Joined:
    Feb 18, 2013
    Posts:
    92
    Yes, but I don't want a list of 100 prefab for that, hm...

    The only solution is to instantiate and keep the item hiden. But I really don't like that
     
  4. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You can also search for it with Resources.Load if you don't want to have a huge list of prefabs in the inspector. You'd then only load the one(s) that you currently need, but that's also a bit slower.