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. Dismiss Notice

Question What is the best approach for a prefab variant which should inherit from TWO prefabs?

Discussion in 'Prefabs' started by AmitChBB, Apr 2, 2023.

  1. AmitChBB

    AmitChBB

    Joined:
    Feb 16, 2021
    Posts:
    36
    Howdy everyone, I would love to consult with others on an issue my team has been facing lately.
    In your opinion, what is the best way to have a prefab variant inherit traits from two separate prefabs?

    For content:

    We have a base prefab for popups in our game. Let's call it `BasePopup` for the sake of argument.

    Every popup prefab inherits from it, for example `YesOrNoQuestionPopup`. This is so all popups inherit things like sprites from it.

    However, we also have a variant of `BasePopup`, called `BasePopupVariant`. It changes the color and textures of some of the images in `BasePopup`.

    I would like to have a `YesOrNoQuestionPopupVariant` which has the diffs from `BasePopupVariant`. However, I would like to ideally not just make a variant of `BasePopupVariant` and replicate all my changes from `YesOrNoQuestionPopup` because with many popups this will take a long time.

    Thanks in advance!
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,863
    At that point I tend to write a script that can do the "change everything to the Variant style" for me, instead of relying on popup variants for style conformity. If you're familiar with CSS, think of the script as doing what a style sheet does. This way it can search the popup's elements and make the color or graphic changes as overrides, and this can be done at Edit or Play time.
     
    AmitChBB likes this.
  3. AmitChBB

    AmitChBB

    Joined:
    Feb 16, 2021
    Posts:
    36
    That's definitely an option. I assume I'll recursively find the elements to alter via the GameObject's name or the name of the sprite attached to it.

    Thanks for the input :)