Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Prefab Copy

Discussion in 'General Discussion' started by Godfreyluck, Apr 14, 2019.

  1. Godfreyluck

    Godfreyluck

    Joined:
    Nov 4, 2018
    Posts:
    3
    Hey all, thanks for this amazing program! I've really loved using Unity. It has honestly changed my life. Right now I'm doing some work with prefabs, and I'm curious about what is going on below the surface of the program. Thanks in advance to anyone who answers my question. I really appreciate the info!

    My question is in regards to copying prefabs:
    When I copy a prefab, how independent is the copy?

    Background info--
    I'm using a prefab as a template for a bunch of other prefabs. I've been running into issues where the animations linked to the copies are un-separable (or I don't know how to separate them.) What I mean by that is, if I change an animation in one, the other also changes. This makes me think that the prefabs don't automatically separate in some ways.

    Also, if I go to change the name of one of the copies, I get the message, "The Prefab file name must match the Prefab root Gameobject name..." This leads me to again believe that the prefabs are still connected in some ways.

    I'm wondering three things. One, is there a reason for having the prefab copies connected to the original? Two, in what ways are they still connected? and Three, what is the preferred method for making/using a prefab template if not by simply copying?
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    1,411
    Hi. There's mutiple ways to use prefabs.

    By copying you're referring to the duplicate feature right? You're not supposed to copy them manually in the explorer.
    If you're using newer prefab system (depends on your Unity version) you can unlink prefabs by right clicking on the game object and selecting Unpack Prefab. This will make it non-related to the previous prefab.

    If you want to have a specific template, but then have some variation - use prefab variations instead.
    This will preserve link to the template and only some values will be changed. Changes to the template will also be transferred to the variations.

    E.g. if you add a script to the template, every variation will have it as well. Or anything else.
     
  3. Godfreyluck

    Godfreyluck

    Joined:
    Nov 4, 2018
    Posts:
    3
    Thank you, xVergilx! That's the perfect response, and now I'm making it all work smoothly.