[Workaround] Godot Viewport Texture Assignment False Error
Learn about this Godot bug involving viewport textures, how to fix it, and which versions of Redot have a fix.
Godot is notorious for ignoring PRs, and has a, not-insignificant volume of devs frustrated with the speed, and, what seems like bias, for merging PRs.
What's a PR?
PRs or "Pull Request", in this context, would be features and fixes contributed by developers who might not be part of the core developer team of a given project.
It looks like Godot has a PR for this viewport texture bug they've been ignoring for nearly 2 years. It's a bug that goes back as far as 6 years (probably more).
Redot on the other hand, found the PR and has the fix implemented and working in their Beta.
If you want to stick to stable versions/ LTS, or you simply don't want to wait till Godot implements it, keep reading.
This workaround solved the issue at runtime, although you may still get the error in the editor. Place this in your _Ready() function
Save your SubViewport texture as a .tscn and then reference it as vpTex (or whatever you prefer) Then use the SetTexture() method on the sprite3D as seen above.
This method works in the latest stable versions of Godot and Redot.
Even after you launch your project with the Redot Beta (v 4.3 Beta 3 mono) you'll need to go into the prefab (subscene) with the Sprite3D and update the path. You'll probably want to enable "local to scene" as well.
That should be it! Make sure you save your "Texture" to your FileSystem and reference it in the script "vpTex".
Other than that, you should be good to go.
If you have any questions, feel free to jump into the comments or hit me up on X/Discord.