Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Read-only prefab fields in in-scene Inspector

Discussion in 'Prefabs' started by PascalTheDog, Aug 7, 2021.

  1. PascalTheDog

    PascalTheDog

    Joined:
    Mar 16, 2015
    Posts:
    86
    Hey,

    Say I'm making a platformer game, and there are plenty of different types of coins the player can collect. They all have their own distinctive features: value, rarity, particle burst, sound effect, etc. Of course, every coin type will have its own prefab which comes with a Coin script.

    The thing is, you can edit an instantiated prefab's fields — and that's no good. We don't want anyone on the team to inadvertently alter the values of those Inspector fields while manipulating the scene. Because individual coins will never deviate from the master type on which they're based (e.g. a red coin is worth 5$ no matter what), those fields being editable in-scene is nothing but a liability.

    We do however want the designer to be able to access and modify those values in the prefab's Inspector as they see fit, should they decide to modify a coin type. Is there any way to "lock" a field on in-scene instantiated prefab, and only allow it to be modified on the actual prefab itself?

    Help would be greatly appreciated. Cheers!
     
  2. Rin-Dev

    Rin-Dev

    Joined:
    Jun 24, 2014
    Posts:
    574