Pakowski
Pakowski

Reputation: 23

How to solve the problem with access to UI elements in Unity?

As far as I understand, in previous versions of Unity it was necessary to write like this, to access UI elements:

using UnityEngine.UI;

But now, in the latest versions, like this:

using UnityEngine.UIElements;

The problem is that when I'm creating two Slider and Text objects, there is no place to attach the Slider object to the script in the Inspector. There is also no such Text class.

[SerializeField] private Text levelText;
[SerializeField] private Slider healthSlider;

Error creating an instance of the Text class

Upvotes: 2

Views: 1764

Answers (1)

derHugo
derHugo

Reputation: 90714

UnityEngine.UIElement is not a replacement for UnityEngine.UI !!! (at least not yet)


You still want to use UnityEngine.UI in your application!

Unityengine.UIElements is currently only for custom editors.

See Unity Manual - UIToolkits.

UIElements: User Interface Elements (UIElements) is a retained-mode UI toolkit for developing user interfaces in the Unity Editor. UIElements is based on recognized web technologies and supports stylesheets, dynamic and contextual event handling, and data persistence.


UnityEngine.UI is now in a built-in package the Unity UI (= ugui) package via the PackageManager (by default it should be installed in new projects)

Upvotes: 2

Related Questions