Search Unity

Feedback [feature suggestion] expose root components in inspector without needing to launch prefab edit mode

Discussion in 'Prefabs' started by enhawk, Mar 3, 2019.

  1. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    The new prefabs system is a great and welcomed update. It does leave two workflows in the dust that did seem quite handy.

    1. Multi editing of prefabs by selecting all prefabs and changing something. Use case 1:

    > I have 150 prefabs and I want to change all transforms by +1 in the Y.

    Use case 2:

    > I have 275 prefabs and they all use a deleted script.

    In the old system we could just select all prefabs and make the change once in the inspector.

    In the new system, we need to edit each one, one by one.

    2. Using prefabs as settings for levels, enemy attack patterns etc. (basically a class with no other components or children that is easy to access for game designers)

    Use case 1:

    > I have 2 attack patterns that I need to change the bullet amount from 6 to 3.

    In the old system we simply select all the attack patterns and change the bullet amount field.

    Use case 2:

    > The art team changed the logo of 150 of the enemy types.

    In the old system we select all the enemy prefabs, select the Sprite field and select the new image, it updates for 150 prefabs in a single click.

    In the new system, each prefab needs to be opened in edit mode individually and the bullet amount field or sprite changed for each one.

    I’m using 2018.3 on a new project and while its great for accessing nested data, having root components exposed in the inspector as before (without going to an edit mode or dragging them all to a scene) would be the best of both worlds.

    If this is already being considered it would be most welcome! :)
     
    Last edited: Mar 3, 2019
  2. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    I remember Unity saying they had to remove this feature to make nested prefabs work but I'm not sure I ever learned the exact reason why. I'll have to do some research on the subject.

    One workaround for multi prefab editing is to:
    1. Open a new empty scene.
    2. Drag all the prefabs you want to edit into this scene.
    3. Select all prefabs and make your edits in the inspector.
    4. With all prefabs still selected apply the overridden values.
    However, I've noticed this doesn't seem to work when it comes to editing the transform values for some reason. So you still need to edit those individually I think. Maybe this is a bug?

    In these cases you'd want to use ScriptableObjects instead. Unless you need the GameObject or Transform for some reason. In fact, using ScriptableObjects could solve most multi editing issues. And in cases when you still need a prefab you could still use them for just certain global shared values, like the enemy logo.
     
    Last edited: Mar 3, 2019
  3. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    While scriptable objects are also a welcome addition, dumping a class on a prefab and putting those in an array was still the shortest and most flexible method for quick results.
     
    Last edited: Mar 4, 2019
    jrumps likes this.
  4. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    Could you give a concrete example of the use case you're taking about here? A ScriptableObject isn't really any different from a MonoBehaviour and in most cases actually simpler because it doesn't have to be attached to a GameObject. So I'm not sure how dumping a class on a prefab is any quicker or more flexible than creating an asset in your project folder.
     
    AnomalusUndrdog likes this.
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    hippocoder likes this.
  6. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    @jrumps

    All you need to do is inherit from ScriptableObject instead of MonoBehaviour and then add the [CreateAssetMenu] attribute above your class definition. This last part will allow you to easily create new editable instances.

    After doing this you can now right-click anywhere in your project folder and select Create and you should see the name of your new script at the top of the menu. Selecting it will create a new instance of that script in your project folder that you can now select and edit it in the inspector.

    Finally, to use your new custom ScriptableObject just make a public field that references it on a MonoBehaviour. Then drop your new ScriptableObject asset on this field in the inspector and then access it's values from the MonoBehaviour.

    A more thorough explanation can be found here.
     
    jrumps likes this.