Swap an instance of a Prefab Variant to another Variant

Hello,

I can’t find a way to do the following Use case :

Prefab : Button
Prefab Variant : Button Green

Prefab : Panel

  • Button
  • Button

I want to create a Prefab Variant : Panel Green, et swap its 2 nested “Button” to “Button Green”

Prefab Variant : Panel Green

  • Button Green
  • Button Green

I didn’t find any UI to easily swap from one variant of an object to another, and couldn’t achieve any editor code to make this.

Could you please help me ?

Cheers

Right, you can’t swap out one Prefab for another as an override. We get how it would be convenient, but it’s not possible at this time. Potential workarounds are things like deactivating one button and adding the green button instead.

Instead of swaping the entire button hierarchy, what about composing the style ?

Have the style in a ScriptableObject, with a MonoBehaviour on the button exposing a parameter of the type of the SO and applying the style values from the SO to the button.

Finally as an override in the Panel Green prefab variant you simply swap the SO reference to the green one.

1 Like