Categories
Unity Programming

Fix Issues Upgrading from Unity 2018 to 2019

When upgrading from Unity 2018 to Unity 2019 or opening a project from 2018 in a Unity 2019 version you can get some errors. Don’t panic, this is to be expected and these can be easily fixed.

UIElements Error

Error: The type or namespace name “ElementName” could not be found

Solution: Remove the namespace .Experimental from the UIElements using statements (at the top of all affected scripts).

2018: using UnityEngine.Experimental.UIElements;
2019: using UnityEngine.UIElements;

GetRootVisualContainer Error

Error: … does not contain a definition for ‘GetRootVisualContainer’ and no accessible extension method ‘GetRootVisualContainer’ accepting a first argument of type

Solution:​ Calls to EditorWindow.GetRootVisualContainer()​ need to be updated to the EditorWindow.rootVisualElement​ property.

2018: EditorWindow.GetRootVisualContainer()
2019: EditorWindow.rootVisualElement​

ClippingOptions Error

Error: The name ‘ClippingOptions’ does not exist in the current context

Reason: The ​ClippingOptions​ property is now split between the ​cacheAsBitmap and style.overflow ​properties​.

Solution: ​Set ​cacheAsBitmap​ to true to trigger bitmap caching, which also requires that the element received has the ​overflow​ property value set to Overflow.Hidden

2018: this.clippingOptions = ClippingOptions.ClipAndCacheContents;
2019: this.cacheAsBitmap = true;

CloneTree Error

Error: The call is ambiguous between the following methods or properties: ‘VisualTreeAsset.CloneTree(string)’ and ‘VisualTreeAsset.CloneTree(VisualElement)’

Reason: VisualTreeAsset.CloneTree no longer accepts a dictionary.

Solution: Call this method without any argument.

2018: VisualTreeAsset.CloneTree(null)
2019: VisualTreeAsset.CloneTree()

AddStyleSheetPath Error

Error: ‘VisualElement’ does not contain a definition for ‘AddStyleSheetPath’ and no accessible extension method ‘AddStyleSheetPath’ accepting a first argument of type ‘VisualElement’ could be found

Reason: AddStyleSheetPath()​ and related methods were removed to decouple UIElements from resources folders.

Solution: You can use the ​styleSheets​ property and explicitly load style sheets via the ​Resources​ class or ​AssetDatabase​ class.

2018: GetRootVisualContainer().AddStyleSheetPath("Assets/styles.uss")
2019: rootVisualElement.styleSheets.Add(Resources.Load("Assets/styles.uss"));

Leave a Reply

Your email address will not be published.