Instantiate gameobject at world position - worldPOS found from clicking on Raw Image

So I’m looking to click on my map to add “markers” on it - like in Hollow Knight’s map system.
My map system is based on a 2nd camera that renders in Orthographic mode and outputs this to a Render Texture, which I then display on a Raw Image in the UI system. My game camera displays in perspective mode.

So I found some answers to help based on this old post

and I’ve implemented that, shown below:

//local coordinates of my render texture's rect       
        RectTransformUtility.ScreenPointToLocalPointInRectangle(_screenRectTransform, eventData.position, null, out Vector2 localClick);

        //my render texture's Y axis is reversed (yMax is 0 and yMin is negative), so I un-reverse this effect on my local click coordinates
        localClick.y = (_screenRectTransform.rect.yMin * -1) - (localClick.y * -1);

        // normalize my local rect coordinates to 0-1 viewport coordinates (correcting for the reverse Y axis again)
        Vector2 viewportClick = new Vector2(localClick.x / _screenRectTransform.rect.xMax, localClick.y / (_screenRectTransform.rect.yMin *-1));

        //use the second camera to convert the viewport coordinates to world coordinates
        Vector2 worldClick = mapCamera.ViewportToWorldPoint(viewportClick);

        //instantiate object at worldClick position
        GameObject clickPoint = Instantiate(pinkPixel);
        clickPoint.transform.position = worldClick;

It kinda seems to work a bit, but I want to be able to zoom in and out in the map, and the orthographic size of the mapCamera creates a huge offset from where I click to where the marker shows up. The more I zoom out (increase orthographic size) - the greater the offset.

I’ve attached an image to showcase what I mean. I traced the room in the map, which should be displaying right on the position where I clicked, but they have an offset and seem to have a scaling issue.

Any ideas?

After SO much time I was able to get the help from someone on Discord that helped me solve this problem.

I will post their answer for any future people having this issue:

**
I was able to reproduce your issue. The problem lies somewhere in your adjustments between getting the inital click coordinates and converting to worldpoint. Seeing potential optimizations I didn’t look into it much further and made this code that does the same:

RectTransformUtility.ScreenPointToLocalPointInRectangle(_screenRectTransform, eventData.position, null, out Vector2 localClick);
Vector2 viewportClick = new Vector2(localClick.x / _screenRectTransform.rect.xMax, localClick.y / _screenRectTransform.rect.yMax);
Vector3 worldClick = mapCamera.ViewportToWorldPoint(viewportClick);
Instantiate(pinkPixel, worldClick + Vector3.forward, Quaternion.identity);

you also need to do one more thing in the editor, namely to change the Pivot on the RectTransform of your RawImage. This makes it so you don’t need to adjust for wierd signums (the part where the mistake lies)