godotengine / godot

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

Materials on instances using viewport textures do not properly interpret nodepaths #96816

Open StrawberrySmoothieDev opened 2 months ago

StrawberrySmoothieDev commented 2 months ago

Tested versions

Reproducible in 4.3stable.

System information

MacBook Air M1

Issue description

When adding a ViewportTexture to a material on an instanced mesh scene, the ViewportTexture tries to interpret the NodePath to the SubViewport as a local path:

(in the scope of itself as the root, ie if the SV is a direct child of the mesh the path would simply be "SubViewport")

when the path is instead generated as a global/absolute path:

Screenshot 2024-09-10 at 3 14 53 PM

(in the scope of the scene owner, ie if the SV is a direct child of the mesh the path would be "MeshNode/SubViewport").

This can be temporarily fixed by manually setting the path, but any changes are reset upon scene reload.

When done with a mesh originally created in a scene, the same process occurs, but functions correctly, therefore my best guess is that a scene being instanced treats nodepaths as local by default. Apologies if this is a duplicate or difficult to understand, this is my first issue. :D

Steps to reproduce

  1. Create a separate scene with a meshinstance3D
  2. Instance that to another scene
  3. Add a SubViewport child to that instance
  4. Add a new StandardMaterial3D, make local to scene, add Viewport texture
  5. Set subviewport as viewport in viewport texture
  6. Reload scene

Minimal reproduction project (MRP)

MRP2.zip

AThousandShips commented 2 months ago

Seems to be a bug in specifically how the editor interprets this combination

StrawberrySmoothieDev commented 2 months ago

Seems to be a bug in specifically how the editor interprets this combination

Most likely, seems that instanced scenes don't realize that they aren't the root. Not sure where this would need to be fixed but I'll do some digging.

AThousandShips commented 2 months ago

Glanced at the code but didn't find anything concrete about where the things are computed, but my immediate suspicion is that it assumes the instanced scene is never the local scene because it's not supposed to be generally, but would be great if you looked around and see!

StrawberrySmoothieDev commented 1 month ago

Seems to be a duplicate of #74331, I'll leave it up to yall to close it but seems to be the exact same issue.