Retain Position and Scale Values of Render Texture Canvas Elements to another Canvas

Now the title might not be able to express the entirety of the question but here’s my problem. In my main scene I have a camera and a canvas in overlay mode, let’s call this “View A”. In this view is a crosshair which position and size I want to manipulate depending on elements inside the canvas of “View B”. “View B” is located in the main scene as a render texture it contains a camera and a canvas in camera space with another crosshair. Now what I want to do is the following: I’m trying to set the position and size of the crosshair in “View A” to practically overlap with the values of the crosshair in “View B”, i.e. if the crosshair in “View B” is in the lower left corner of its screen I’d like the crosshair in “View A” to be in the same position with the same size but in the canvas of “View A”.

What I’m currently capable of is setting the crosshair in “View A” to the same location as the crosshair in “View B” but only if the crosshair in “View B” is in its origin, as all I have to do in that case is to get the origin of the render texture quad in the screen space of “View A” canvas. I do this in the following way:

CursorTransform.localPosition = localPoint;```

But now I'm stuck in figuring out how to get a scale factor that makes the crosshair in "View A" and "View B" look the same size and how to adjust the position of the crosshair in "View A" depending on the position of the crosshair in "View B".

Getting RectTransform / Canvas rendered stuff nailed down to your scene can be tricky. It can be even trickier if you run on different-shaped monitors, such as 4:3, 16:9, 16:10, etc. Here are some key things to keep in mind:

  • use the right anchoring. Get familiar with what anchors do, especially how they cascade from parent to child

  • you have multiple coordinate spaces to reason about: the pixels in your screen, the units of your canvas (based on how you scale stuff) , and then the sub-area (inner box) you have above

Generally getting the ratio between the base Canvas and the RectTransform where stuff is happening is going to be your win to tell where you are in Screen coordinates.

Personally when I tackle these things I start with one layer and get the coordinates nailed down so they come back right in Screen coordinates, then commit that change. Then I work the screen coordinates back to the other rectTransform.

It can be very fiddly. Use LOTS of Debug.Log() outputs to see where positions are being placed!