How do I "fake" the mouse position by overriding the base input class?

I have a world space canvass and can interact with a button on said canvass with my mouse. I will be locking the cursor though which disables said interaction. I’ve looked up some posts on creating custom input modules to replace the stand alone input module and am having a difficult time with it.

One solution was to override the mouse position in the BaseInput class and pass in a Vector2.zero. I have disabled the standalone input on my EventSystem GO and added the following scripts from another post.

using UnityEngine; using UnityEngine.EventSystems;

[RequireComponent(typeof(MyBaseInput))]
public class MyInputModule : StandaloneInputModule
{
    protected override void Start()
    {
        this.inputOverride = GetComponent<MyBaseInput>();
        base.Start();
    }
}

using UnityEngine;
using UnityEngine.EventSystems;

public class MyBaseInput : BaseInput
{
    public Vector2 CursorPosition = Vector2.zero;

    public override Vector2 mousePosition
    {
        get { return this.CursorPosition; }
    }
}

I am clearly missing a core concept here… in my mind this should be overriding the mouse position to the center of the screen. Am I completely off the mark here?

Found a solution to my problem via this link VR Gaze Input | TALES FROM THE RIFT

Thanks to Peter Koch and his code I was able to determine that most of the functions I required were in the PointerInputModule and I could “fake” a mouse position with it’s pointerEventData.position.

The following is the boiled down code I am using since I am not implementing a VR system and will continue to modify as I require a Vector3.Distance from my player to the worldspace buttons in question. Hope this helps someone else!

using UnityEngine;

using UnityEngine.EventSystems;

using System.Collections.Generic;

public class WorldSpaceUIModule : PointerInputModule
    {
        public string ClickInputName = "Submit";
        public RaycastResult CurrentRaycast;
    
        private PointerEventData pointerEventData;
        private GameObject currentLookAtHandler;
    
        public override void Process()
        {
            SetPointerPosition();
            HandleRaycast();
            HandleSelection();
        }
    
        private void SetPointerPosition()
        {
            if (pointerEventData == null)
            {
                pointerEventData = new PointerEventData(eventSystem);
            }
    
            // fake a pointer always being at the center of the screen
            pointerEventData.position = new Vector2(Screen.width / 2, Screen.height / 2);
            pointerEventData.delta = Vector2.zero;
        }
    
        private void HandleRaycast()
        {
            List<RaycastResult> raycastResults = new List<RaycastResult>();
            eventSystem.RaycastAll(pointerEventData, raycastResults);
            CurrentRaycast = pointerEventData.pointerCurrentRaycast = FindFirstRaycast(raycastResults);
    
            ProcessMove(pointerEventData);
        }
    
        private void HandleSelection()
        {
            if (pointerEventData.pointerEnter != null)
            {
                GameObject handler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(pointerEventData.pointerEnter);
    
                if (currentLookAtHandler != handler)
                {
                    currentLookAtHandler = handler;
                }
    
                if (currentLookAtHandler != null && Input.GetMouseButtonDown(0))
                {
                    ExecuteEvents.ExecuteHierarchy(currentLookAtHandler, pointerEventData, ExecuteEvents.pointerClickHandler);
                }
            }
            else
            {
                currentLookAtHandler = null;
            }
        }
    }