[Bug] [PolySpatial 1.2.3] Move the Canvas at runtime make the interaction with it not work correctly

, ,

Hi!

I need move the canvas depending of the dimension of the VolumeCamera in bound mode, but, when I move it, I cannot interact correctly with the buttons inside to that canvas.

Steps:

  1. Create a scene.
  2. Add a VolumeCamera in bound mode with both dimension in (x:1.28; y:0.72; z:0.25).
  3. Add the component VolumeCameraResizeListener to the GameObject that has the component VolumeCamera.
  4. Copy the EventSystem of the scene UGUI of the sample of PolySpatial and paste it in your scene.
  5. Copy the SceneCamera of the scene UGUI of the sample of PolySpatial and paste it in your scene.
  6. Create a Canvas equals to the scene UGUI of the sample of PolySpatial but without childs.
  7. Add the script VolumeCameraFollower attached in this post with the fields:
    Offset: (0; 0; 0.01)
    Is Bounded: true
    Horizontal Alignment: Center
    Vertical Alignment: Middle
    Depth Alignment: Back
    Volume Camera: (set the reference)
  8. Add a button as a child of the Canvas
  9. Test in the simulator or with a physical device, you will see that is difficult click the button pointing to it with the eyes.

I know that we can use the Guest Mode to improve the tracking of our eyes but I also tested it without my component and work fine.

Move the Canvas at runtime is not supported?
I should call a magic function of PolySpatial after move the Canvas to make it work correctly?

Thanks!

using Unity.PolySpatial;
using UnityEngine;

namespace Enviz.AppleVisionProDemo.Runtime
{
    public class VolumeCameraFollower : MonoBehaviour
    {
        [Header("Settings")]
        [SerializeField] private Vector3 m_Offset = default;
        [SerializeField] private bool m_IsBounded = default;
        [SerializeField] private HorizontalAlignmentTypes m_HorizontalAlignment = HorizontalAlignmentTypes.Center;
        [SerializeField] private VerticalAlignmentTypes m_VerticalAlignment = VerticalAlignmentTypes.Middle;
        [SerializeField] private DepthAlignmentTypes m_DepthAlignment = DepthAlignmentTypes.Middle;

        [Header("References")]
        [SerializeField] private VolumeCamera m_VolumeCamera = default;

        private void Update()
        {
            if (m_VolumeCamera == null)
            {
                return;
            }

            if (!m_IsBounded)
            {
                transform.position = m_VolumeCamera.transform.position + m_Offset;
                return;
            }

            var x = m_HorizontalAlignment switch
            {
                HorizontalAlignmentTypes.Left => m_VolumeCamera.Dimensions.x / -2f,
                HorizontalAlignmentTypes.Center => 0f,
                HorizontalAlignmentTypes.Right => m_VolumeCamera.Dimensions.x / 2f,
                _ => throw new System.Exception($"Not supported: {m_HorizontalAlignment}"),
            };
            var y = m_VerticalAlignment switch
            {
                VerticalAlignmentTypes.Top => m_VolumeCamera.Dimensions.y / 2f,
                VerticalAlignmentTypes.Middle => 0f,
                VerticalAlignmentTypes.Bottom => m_VolumeCamera.Dimensions.y / -2f,
                _ => throw new System.Exception($"Not supported: {m_VerticalAlignment}"),
            };
            var z = m_DepthAlignment switch
            {
                DepthAlignmentTypes.Front => m_VolumeCamera.Dimensions.z / 2f,
                DepthAlignmentTypes.Middle => 0f,
                DepthAlignmentTypes.Back => m_VolumeCamera.Dimensions.z / -2f,
                _ => throw new System.Exception($"Not supported: {m_DepthAlignment}"),
            };

            transform.position = m_VolumeCamera.transform.position + m_Offset + new Vector3(x, y, z);
        }

        public enum HorizontalAlignmentTypes
        {
            Left,
            Center,
            Right
        }

        public enum VerticalAlignmentTypes
        {
            Top,
            Middle,
            Bottom
        }

        public enum DepthAlignmentTypes
        {
            Front,
            Middle,
            Back
        }
    }
}

When you created the canvas, was it in world space, and did it have a Graphic Raycaster component?

I believe I followed your steps exactly, with one exception: after I copied the Home Button Text and Icon GameObject from the UGUI sample scene, I added a GraphicRaycaster to it before deleting its children and adding a Button. After doing that, I was able to click the button as expected.

It is supported. If you can reproduce your issue in a bug report and let us know the incident number (IN-#####), we can investigate what might be going wrong.

I think I now know what exactly is causing the problem.

Placing the canvas too close to the front boundary in bounded mode causes the button interaction to malfunction. My component (shared in the post) moves the canvas to the front of the boundary, did you test it with my component or just moving the canvas? That’s probably why it worked for you and not for me.

Anyway, I added a larger offset and it works. Thanks!

Edit: I will try get time to make a official report with a project of example.

1 Like

I used your component, but it’s likely that I didn’t have exactly the same setup in terms of volume camera, button placement, etc.; I remember I had to manipulate the button position to get it to fit in the volume. Anyway, thanks for the update!