Embedded Value Providers in Prefabs

  9. Problems & Solutions No Comments

Issue

Due to a limitation with Unity’s serialization system, embedded value providers cannot be serialized directly as part of prefab assets.

Solution 1: Create Asset

You can get around this limitation by adding the [CreateAssetMenu] attribute to your value provider, and creating assets to back them.

You can then drag-and-drop the value provider assets into the Init argument fields on your prefab, and they can be serialized.

Solution 1: Create Sub-Asset

Another way to bypass the limitation is to the convert the embedded value providers into sub-assets of the prefab asset.

You can do this by right-clicking an embedded value provider on a prefab instance in the Inspector, and selecting ‘Make Sub-Asset of Prefab‘.

   

You can reverse the process by right-clicking the value provider in the prefab instance again, and selecting ‘Embed Into Prefab Instance‘.

Leave a Reply

Your email address will not be published. Required fields are marked *