Search Unity

Acces prefab names in script?

Discussion in 'Scripting' started by Pelajesh, Jul 25, 2011.

  1. Pelajesh

    Pelajesh

    Joined:
    Dec 7, 2009
    Posts:
    363
    I was just wondering if it is possible to access prefab names from a script.
    For example if I have a Transform variable and I set its value to a prefab named "Arrow" from inspector, then would it be possible for me to get that same string "Arrow" in the script?
     
  2. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
  3. bdev

    bdev

    Joined:
    Jan 4, 2011
    Posts:
    656
    Yea, you can access everything from prefabs, including .name. You have to be a little careful on modifying variables of a prefab as most of the time they will be saved. Just keep in mind that Awake / Start does not get called on prefabs, just their instances. So if you need to run some code from a prefab's script you've got to use OnEnable or OnDisable