I am searching now for almost an hour and I cannot figure out how correctly to select the background image and position of a visual element.
The query docu is really poor, there is literally nothing:
UQuery is a set of extension methods allowing you to select individual or collection of visualElements inside a complex hierarchy.
All the youtube guys show the same example with a Button.
I have this structure:
Each "Layer" contains a background image:
Here is my code:
public class ParallaxController : MonoBehaviour {
public VisualElement layer_0;
public Image layer_0_0;
public Image layer_1;
public Image layer_1_1;
public Image layer_2;
public Image layer_2_2;
public Image layer_3;
public Image layer_3_3;
public Image layer_4;
public Image layer_4_4;
// Start is called before the first frame update
void Start() {
var root = GetComponent<UIDocument>().rootVisualElement;
layer_0 = root.Q<VisualElement>("Layer_0");
Debug.Log(layer_0.style.backgroundImage);
Debug.Log(layer_0.style.backgroundImage.value.sprite);
Debug.Log(layer_0.style.backgroundImage.value.texture);
Debug.Log(layer_0.style.position);
//Debug.Log(layer_0.Q.<Image>());
//Debug.Log(layer_0.Q.<Background>());
}
// Update is called once per frame
void Update() {
}
}
Its always Null