Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to retroactively apply prefab?

Discussion in 'Prefabs' started by MaxLohMusic, Jun 7, 2023.

  1. MaxLohMusic

    MaxLohMusic

    Joined:
    Jan 17, 2022
    Posts:
    45
    Say I have two prefabs, enemy and player. And I realized they have some parts in common such as Collider and Rigidbody. So, I make a new prefab called "Animatable". Then I want Enemy and Player to both extend from this Animatable. How do I tell Unity to make them both descend from this parent prefab without needing to manually re-make both of them?
     
  2. rysan007

    rysan007

    Joined:
    Sep 1, 2022
    Posts:
    2
    I think the tool you are looking for is Prefab Variants. https://docs.unity3d.com/Manual/PrefabVariants.html

    You can right click > Create Prefab Variant, or drag your premade prefab into the scene, and choose Variant instead. This will have a base Prefab that they will inherit from.
     
  3. MaxLohMusic

    MaxLohMusic

    Joined:
    Jan 17, 2022
    Posts:
    45
    I have used prefab variants before but it seems to be different from the question I'm asking. How would I retroactively apply the prefab (or prefab variant) to the object which was made without using a prefab? In other words, we have an "unpack" option which dissociates an object from its prefab.. what about the reverse, where I made the object before I realized I'd want to make it a prefab, and want to newly associate it with a prefab
     
  4. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    530
    For the most part you can't. In some cases you can manually edit the prefab .meta files but it's messy, not very reliable and likely to break stuff. I have seen a couple of posts discussing that approach.

    Starting with Unity 2022 they added some options for replacing the prefab of existing instance or reconnecting unpacked prefab. https://blog.unity.com/engine-platform/prefabs-whats-new-2022-2 It's better than having nothing, but it has it's limitations and you still can't change the base of existing prefab or a variant. Make sure you are using version control or have a backup of your project when trying out this feature.
     
    MaxLohMusic likes this.