• 3D
  • Strange behavior when moving Sprite3D with Viewport as child

Hi,

I've been trying to set up a button prompt icon that fades in over interactive objects (npc's, level exits etc). My method so far has been to add a billboard Sprite3D to each interactive object and add a viewport to the Sprite3D (as a child) with Usage: 2D switched on. I then add a TextureProgress to each viewport so that the prompt can be edited over time. So far this looks like:

Spatial (base object) -> Viewport -> TextureProgress

This works ok. With a bit of simple code, the button fades in when the player is near to the object and fades out when moving away. The problem is that if another (transparent) object moves in front of the prompt, the prompt is obscured by it. Ideally I'd like to render the viewports in front of everything else in the scene, including objects with transparent materials with a fixed render priority. However, there appears to be no way to get a viewport to render in front of these.

And so, the main problem: as a last resort I have added some code that constantly positions the Sprite3D at a location in 3D space between the interactive object and the camera, so that it is always physically in front of everything else. This works perfectly when I adjust the translation values for the Sprite3D before building/launching the game, but if I adjust these translation values in the editor while the game is running (or add the positioning code I mentioned earlier) the viewport disappears. Even if I move the Sprite3D a tiny amount, the viewport seems to be permanently removed/hidden, however if I do the exact same thing before running the game it displays as normal. It seems that Godot does not like these translation values adjusted in real time.

Has anyone else encountered this behavior and maybe found a workaround / alternative method?

Many thanks!

Ok, so after a lot of frustrating trial and error I have eventually managed to assign a viewport to my material override as a texture AND keep the render priority of the override material. In the end, I chose the "Viewport texture" option in the material override's albedo texture dropdown and this seems to work, however there is an error message appearing when the game starts:

Node not found: IndicatorViewport ViewportTexture: path to node is invalid

... which is clearly not the case, as I selected the viewport node through the GUI. So, just to clarify, there doesn't (currently) seem to be any way to successfully assign a viewport as a texture to a Sprite3D override material in C Sharp, and if this is attempted through the GUI it sort-of works (however, the error message above is shown).

If anyone else encounters this bug then this post from two years ago detailing the issue might be useful.

https://github.com/godotengine/godot/issues/16067

They mention that a potential work-around is to move the viewport that you are referencing to a node higher-up than the node that is referencing it. This appears to have solved the problem for me (the errors no longer appear).