Search Unity

Replacing Prefab Instance with variant

Discussion in 'Testing & Automation' started by matsuda-san, Feb 11, 2021.

  1. matsuda-san

    matsuda-san

    Joined:
    Apr 18, 2018
    Posts:
    1
    Hello,
    I'm trying to write an editor script which automates replacing prefabs while preserving modifications made in parent prefab as overrides and references to children of nested prefab.

    I use YamlDotNet parser to traverse the prefab, find PrefabInstances and replace proper guids. So far with this method I can replace prefab with another prefab and preserve modifications but if I use prefab variant instead modifications are not applied in the editor.

    After short investigation I have found that m_CorrespondingSourceObject fileID mismatch is causing the problem but I can't find a way how to get proper fileID. In case of a regular prefab fileID simply matches document id in referenced prefab asset file but with variant I have no idea where does it come from. I looked through the .prefab and .meta files of base and variant prefab with no luck. I assume it is somehow calculated with some kind of hash function based on prefab name but I'm not sure.

    Any help is appreciated!