Description:
When using a reference atlas for a Widget that will be instantiated while being inactive, the replacement atlas that was used for the creation of the widget will be used instead of the current replacement atlas, this caused me quite a headache due to heavy ram usage.
How to reproduce:
- Create an HD and an SD Atlas
- Create a reference atlas and set the HD as replacement
- Create a UI with a widget, use the reference atlas for the widget
- Set the widget to inactive and create a prefab from it
- Delete the widget in the scene
- Write a script that switches the reference atlas's replacement to sd and attach it to the root of the menu
- Add some lines to the script that instantiate the widget
- Run the scene
- Select the HD atlas texture in the project folder, go to Asset > Find References in Scene, notice how the widget references the hd atlas although it shows the reference atlas as atlas and this is switched to sd
- Activate the widget, notice how now all references to the hd atlas are deleted and it now uses the correct replacement although the used atlas didn't change.
Workaround:
Instead of setting the widget to inactive, let it be active at the time of Instantiate but add a script to it that calls gameObject.SetActive(false) (Unity 4) or gameObject.SetActiveRecursively(false) (Unity 3.x) in the Start() function