engine icon indicating copy to clipboard operation
engine copied to clipboard

When the `UICanvas.renderMode` is `CanvasRenderMode.ScreenSpaceCamera`, if the `camera.entity` is the same as the `canvas.entity` or a child of the `canvas.entity`, it will fall into an infinite loop.

Open cptbtptpbcptdtptp opened this issue 10 months ago • 4 comments

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context Add any other context about the problem here.

cptbtptpbcptdtptp avatar Feb 14 '25 07:02 cptbtptpbcptdtptp

当画布的渲染模式为 ScreenSpaceCamera ,但相机节点为画布的子节点时: 相机节点的世界坐标改变 ----> 影响画布节点的世界坐标 画布节点的世界坐标改变 ----> 影响相机节点的世界坐标 相机节点的世界坐标改变 ----> 影响画布节点的世界坐标 画布节点的世界坐标改变 ----> 影响相机节点的世界坐标 相机节点的世界坐标改变 ----> 影响画布节点的世界坐标 画布节点的世界坐标改变 ----> 影响相机节点的世界坐标 …死循环…

cptbtptpbcptdtptp avatar Feb 14 '25 07:02 cptbtptpbcptdtptp

看了一下 Unity 在这部分做的处理,首先在正常情况下(相机节点不是画布的子节点):

Image

然后将相机节点拖到画布中:

Image

可以发现,当相机节点为画布子节点时,画布不随着相机位置改变而改变。这样也有点突兀(至少在文档中描述起来比较难理解)。

cptbtptpbcptdtptp avatar Feb 14 '25 07:02 cptbtptpbcptdtptp

我理解现在这种模式下,当相机不是画布的子节点,调整相机的坐标啥的,你是动态调画布节点的 Transform 来适配相机,当相机是子节点的时候,死循环了对么?

singlecoder avatar Feb 14 '25 07:02 singlecoder

我理解现在这种模式下,当相机不是画布的子节点,调整相机的坐标啥的,你是动态调画布节点的 Transform 来适配相机,当相机是子节点的时候,死循环了对么?

是的,如果是相机模式下,需要遵循: 「画布和相机的相对位置不变」 那么相机的世界坐标改变的时候,画布的世界坐标也应该改变,本来这个改变应该是由相机主导,画布跟随的,但是如果相机是画布的子节点,那么在画布跟随改变后,又转头影响相机的世界位置,然后就死循环。

cptbtptpbcptdtptp avatar Feb 14 '25 07:02 cptbtptpbcptdtptp