I tested UI mouse picking with raycast tutorial (HOWTO: Raycast UI | Flax Documentation).
I added a test control on root (100,100), and used raycast call as tutorial mentioned.
(HOWTO: Creating UI from code | Flax Documentation)
using System;
using System.Collections.Generic;
using FlaxEngine;
using FlaxEngine.GUI;
namespace Game;
/// <summary>
/// RootUI Script.
/// </summary>
public class RootUI : Script
{
ContainerControl rootUI;
private ProgressBar _healthBar;
/// <inheritdoc/>
public override void OnStart()
{
// Here you can add code that needs to be called when script is created, just before the first game update
}
/// <inheritdoc/>
public override void OnEnable()
{
// Here you can add code that needs to be called when script is enabled (eg. register for events)
rootUI = RootControl.GameRoot;
_healthBar = new ProgressBar
{
Width = 120,
Parent = RootControl.GameRoot,
Location = new Float2(100, 100)
};
_healthBar.Value = 100;
}
/// <inheritdoc/>
public override void OnDisable()
{
// Here you can add code that needs to be called when script is disabled (eg. unregister from events)
_healthBar.Dispose();
_healthBar = null;
}
/// <inheritdoc/>
public override void OnUpdate()
{
// Here you can add code that needs to be called every frame
var pos = Input.MousePosition;
if (rootUI.RayCast(ref pos, out var hit))
{
Debug.Log("UI hit over: " + hit.GetType().Name);
}
}
}
And added the script to the default scene.
But raycast was returning strange result - picking message was trigerred in the region at the upper left of the actual control.
It was not just shifted - the reacting region was much smaller than the actual control size.
I removed Location property setting of the control to move it to the origin (0,0), but the raycast activation zone was still much smaller than the actual control.
I tested with the Button control, and the result was the same. So it might be not from the special characteristic of Progress control in tutorial.
And the script does not have a panel or scaler parent to mess up with, so I didn’t have options to change the Render space modes.
I am curious where this phenomenon comes from.