Search Unity

How to create an array of prefabs with editor available for each of them

Discussion in 'Scripting' started by Criperum, Nov 10, 2018.

  1. Criperum

    Criperum

    Joined:
    Aug 7, 2014
    Posts:
    3
    Hello.
    I have a game object with an array for prefabs. I'm exposing this array to editor so i can drag-n-drop prefabs i want into this array. But those prefabs need to be adjusted using properties of scripts inside them. So my question is how to add those parameters to the array editor (i suppose i'm going to need custom editor)? I want to see those paramters under each array element so that i can expand and adjust them before launching. Also how can i filter those prefabs on drag stage so only prefabs with certain components (like scripts that inherit some base script) can be placed in that array?
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    That's not how prefabs work. Prefabs are 'shrink-wrapped' and can't be changed when you place them into an array in editor. You need to pre-set the changes for each, then create a new prefab from that, and then add those to the array.
     
  3. Criperum

    Criperum

    Joined:
    Aug 7, 2014
    Posts:
    3
    What if I override drag-n-drop behaviour of editor so when i drop prefab on it i instantiate it and provide settings of gameobject to be set? Will this work?