Search Unity

Set a prefab's variable to never update when a prefab is updated?

Discussion in 'Editor & General Support' started by J_P_, Jun 20, 2013.

  1. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    Updated OP to better communicate what I'm asking.

    Basically, what I want is a prefab where I can specify certain variables or attributes to ignore when updating instances of that prefab.

    Imagine I have a prefab for a piranha plant that shoots fireballs (using this as an example to illustrate the problem)

    $180px-Piranha_Plant.JPG

    Not all piranha plants will shoot at the same speed, so I have a float variable that determines how fast it shoots. I also have a child object that the level designer positions -- it tells the piranha plant where it will be when it's fully extended out of the tube (different instances might go higher or lower or to the left a bit etc).

    The problem comes when updating the prefabs -- since the manipulation of prefabs is limited within the Project view, I often have to change an instance of a prefab and then drag it over to overwrite/update it. This resets the default values and positions of child objects.

    Any instance of the piranha plant that happened to use the old default fire rate value (unbolded) will be changed to the new default value (whatever was set for the instance that I used to update the prefab with), breaking the levels they were in.

    Additionally, the position of the guide object telling the piranha plant where to extend to will be reset for every single instance, which again breaks all the levels they were in.

    The only workaround I can think of is to not use child position and instead make it a v3, and then be super diligent about making sure those values are ALWAYS bold to override the default values. With an editor script I could make the vector3 about as easy to manipulate as the child transform I was using before, but having to make sure everything is bold to override the default is still a HUGE hassle (some of these prefabs have several variables that should be unique to that instance).

    I figure this sort of thing isn't entirely uncommon, so I'm hoping someone has suggestions on how to handle this better.

    What I'd really like is to be able to specify certain variables or children to be entirely ignored when updating prefabs. So if I set a specific instance's fireRate float to 2.3, the only way to update it for that instance is to select that specific instance and change it. I obviously don't want to totally disconnect the entire instance from the prefab though -- just certain variables. Is there something like [OverridePrefab] hidden somewhere in the docs? Any other tips?

    Original post:
     
    Last edited: Jul 25, 2013
  2. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    Updated OP to better communicate what I'm asking. Any ideas?
     
  3. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    Tried a custom editor class to utilize SerializedProperty.prefabOverride, but

    "Set prefab override to true is not supported"

    =/
     
  4. deis

    deis

    Joined:
    Sep 17, 2009
    Posts:
    29
    Trying to bring more attention to this. I ran into an instance where this would be most helpful. Some sort of [PrefabIgnore] meta on a variable would be amazing.

    [PrefabIgnore] : Changes to this variable on instances of this prefab are ignored when applied.

    This would be incredibly helpful when handing things off to Level Designers for a game. I do not want them to accidentally Apply some changes of an instance to the prefab.
     
    Last edited: Jan 19, 2014
  5. MDragon

    MDragon

    Joined:
    Dec 26, 2013
    Posts:
    329
    Sorry if I skipped the OP if the topic at hand is difference, but here's where I found the instructions:
    http://answers.unity3d.com/questions/232670/how-to-detach-an-object-from-prefab.html

    I actually knew this was possible by accidentally finding this out by having a complicated prefab with several objects, and when trying to move some objects out and about, it asked me if I wanted to break the prefab connection.

    Also, I didn't test this:
    http://docs.unity3d.com/Documentation/ScriptReference/PrefabUtility.DisconnectPrefabInstance.html
    (And the PrefabUtility other options may be useful for a scripting option)
     
    Last edited: Jan 19, 2014
  6. deis

    deis

    Joined:
    Sep 17, 2009
    Posts:
    29
    Thanks for pointing these out. The "PrefabUtility.DisconnectPrefabInstance" could work, but I would prefer not to have it detached so it can pickup changes to other variables on the prefab in the future.
     
  7. gametr4x

    gametr4x

    Joined:
    Apr 22, 2009
    Posts:
    86
    Has anybody found a way to force dirty a variable like this yet? I'd really like to be able to change the default starting value on a prefab without it screwing up all the hundreds of objects that have already been placed which use a different default value.
     
  8. zander_m

    zander_m

    Joined:
    Feb 7, 2019
    Posts:
    15
    Responding to old threads that turn up in search results.
    I am not affiliated with and have never used this package, but it claims to do exactly what you're wanting: https://assetstore.unity.com/packages/tools/easy-prefab-override-21193
     
    leohilbert likes this.
  9. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    @J_P_ Unity does this for RectTransform.
    So what you really want to do is already there.

    UnityGuys, If this is not an internal api please let us now, how we can also mark our properties as transient for prefabs.