Whenever I try to access the styles which I set in the inspector via script I am always getting the default values.
I made a new clean project and this time I am also using my own Theme file. I added an image and gave it width 1397px, but when I access the width in my script, then its 0, which is the default value.
Here is the code and a reference image, there is literally nothing more there:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
public class Arena_UI_Controller : MonoBehaviour {
// Start is called before the first frame update
void Start() {
var root = GetComponent<UIDocument>().rootVisualElement;
VisualElement arena = root.Q<VisualElement>("Arena");
Debug.Log(arena.style.width.value); // Should be 1397px
}
// Update is called once per frame
void Update() {
}
}
Also, what is the best practice with the Theme Style Sheets? Per default it is always the UnityDefault, but should I create my own for every seperate UI Document?
Here is also a a screenshot of the panel settings: