Instantiate a prefab on the canvas at the mouse position

I’ve scoured so many forums for this and watched so many tutorials, and can’t seem to get it right.

All the interactions in the game I’m making come from a mouse click. I want to then have the options in button form appear around the mouse.

My issue is taking the mouse position and converting it to canvas coordinates. (or if I can get the mouse position on the canvas at the beginning, that also works). The closest I’ve gotten is the prefab appearing just outside the canvas. From my understanding, the issue stems from the middle of the canvas being 0,0 I haven’t tried changing the anchor point of the canvas, but would that affect other gameobject resizing when he canvas resizes?

Since there’s no answer here in nearly a day - Have you asked this to an AI with some more details?
I recall to have had this same usecase some time ago and ChatGPT got me there after a little trial and error.
It’s not the quickest to describe because it requires some code as well as correct arrangement in the editor.

This is very easy. Seems too easy to search on forums and too easy to ask AI :grinning_face:
Place the button somewhere outside the screen and then use this code to get it in the middle of button click.

        if (Input.GetMouseButton(0))
        {
            button.GetComponent<Image>().rectTransform.position = Input.mousePosition;
        }

well you can tell where the mouse click was by the mouse position, so if you’re making something like a context menu, you can use the mouse position as top left (or adjust with an offset if you wish) .. so for example while I have no idea what youre doing this worked for me

    [SerializeField] private GameObject prefab;
    [SerializeField] private GameObject canvas;
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Instantiate(prefab, Input.mousePosition, Quaternion.identity, canvas.transform);
        }
    }

which makes a button wherever i clicked the button, so, you can instantiate your menu, or, enable+move your menu, or whatever it is that you wanted