godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.28k stars 21.05k forks source link

Editable Children = on breaks paths to instanced SubViewports & manual fixes are not retained #87809

Open paulmiller opened 8 months ago

paulmiller commented 8 months ago

Tested versions

reproduced in 4.0.4.stable & 4.2.1.stable

System information

Godot v4.2.1.stable unknown - Arch Linux #1 SMP PREEMPT_DYNAMIC Fri, 05 Jan 2024 16:20:41 +0000 - Tty - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1070 (nvidia; 545.29.06) - Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz (8 Threads)

Issue description

If a scene instances another scene with "Editable Children" enabled, and the child scene contains a SubViewport, and a material rendering that SubViewport, the material's "Viewport Path" will be wrong. It'll render a magenta texture instead of the SubViewport. You can fix the path manually, but the editor revert to the wrong path after reloading.

Steps to reproduce

The attached subviewport_instance_tests.zip has 2 Godot projects, standard_project & shader_project. They demonstrate the same problem, using a StandardMaterial3D and a ShaderMaterial. I tried both projects under Godot 4.0.4 & 4.2.1 and got the same results all 4 times.

Consider standard_project. Scene A has:

A
├ Camera3D
├ MeshInstance3D
└ SubViewport
  ├ Camera3D
  └ Label3D (text = "A")

The MeshInstance3D displays the SubViewport. Running scene A (open a.tscn in the editor > right click the "a" tab > "Play This Scene") works as expected - "A" appears on the MeshInstance3D.

Scene B instances A:

B
├ Camera3D
└ A

Running scene B also works as expected.

Scene C is exactly like B, except C's A instance has "Editable Children" enabled. In C, the MeshInstance3D shows a solid magenta texture, and there's an error, "ViewportTexture: Path to node is invalid".

It seems that "Editable Children" causes the ViewportTexture's viewport_path to be interpreted as an absolute path from the root (the C node).

I tested this with scene D. D is like C, except I added a SubViewport at that absolute path:

D
├ Camera3D
├ A
└ SubViewport
  ├ Camera3D
  └ Label3D (text = "D")

Playing scene D, A's MeshInstance3D shows "D", not "A".

We can fix scenes C and D manually:

Now C and D work as expected. But this only helps temporarily - certain combinations of opening, saving, & closing cause the viewport_path to revert. It's a bit hard to repro, but this sequence seems to trigger it pretty reliably:

You can try the same steps in shader_project and get the same result. The ViewportTexture is a uniform named tex. You can fix tex in the material inspector, but it also gets reverted.

Minimal reproduction project (MRP)

subviewport_instance_tests.zip

addmix commented 4 months ago

Can confirm, have the same issue with editable children and viewport paths. I'm on Windows 11 and 4.2.2.

clarence112 commented 2 months ago

Can also confirm, Pop!_OS 22.04, GD 4.2.2

Seems to be the same issue as #84607