Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False error "Viewport Texture must be set to use it." #66247

Closed
rarsp opened this issue Sep 22, 2022 · 45 comments · Fixed by #97029
Closed

False error "Viewport Texture must be set to use it." #66247

rarsp opened this issue Sep 22, 2022 · 45 comments · Fixed by #97029

Comments

@rarsp
Copy link

rarsp commented Sep 22, 2022


Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.


Godot version

4.0 beta 1 mono

System information

Windows 10

Issue description

Scenes with viewport shows this errors even though viewport textures are set and working in materials:

ERROR: Viewport Texture must be set to use it.
at: (scene/main/viewport.cpp:114)
ERROR: Viewport Texture must be set to use it.
at: (scene/main/viewport.cpp:109)

Steps to reproduce

Create simple scene with viewport and material that is using it as texture.

Minimal reproduction project

No response

@Rindbee
Copy link
Contributor

Rindbee commented Sep 22, 2022

I guess the ViewportTexture is obtained by instantiating it instead of getting it from an existing Viewport. Some properties need to be set before it can be used. The error message is really not very detailed either.

@isaaccp
Copy link
Contributor

isaaccp commented Feb 11, 2023

I keep getting this too (in GDscript), but otherwise my SubViewport works fine.

@PedroPareja
Copy link

I got this same situation/error. The viewport texture does not work when exporting (it does work when executing from the editor)

@PedroPareja
Copy link

PedroPareja commented Feb 13, 2023

I found the solution here: #55471

I set the SubViewport update mode to always to fix the problem. It seems there's a bug with "update only when visible" option and it has not been fixed yet

@Withaust
Copy link
Contributor

Withaust commented Feb 21, 2023

In RC2 this error seems to be happening even with the update mode set to always... or any other mode, actually

isaaccp added a commit to isaaccp/Stuffie that referenced this issue Feb 25, 2023
This ... swaps error for a different one and reduces the verbosity of
them slightly.

godotengine/godot#60350
godotengine/godot#66247
etc
@KettLovahr
Copy link

KettLovahr commented Feb 27, 2023

Yes, I'm having the same issue, no matter what configuration the SubViewport uses, it will act as if there's no Viewport set on debug or on the editor once the scene is reloaded. Spitting out the same "Viewport Texture must be set to use it." When already is set.

@1419427247
Copy link

image
V4.0. table. official [92bee43] Still the same

@baschermann
Copy link

baschermann commented Mar 21, 2023

Godot version

4.0.1 RC2 mono

System information

Windows 10

Issue description

Scenes with viewport as a 3D texture shows errors on game startup. Mesh materials from viewport (2D) textures do not work and show up purple ingame, even though they show up in the editor.

E 0:00:00:0832 get_height: Viewport Texture must be set to use it.
<C++ Error> Condition "!vp" is true. Returning: 0
<C++ Source> scene/main/viewport.cpp:116 @ get_height()

These appear as errors, even though they work except for the mesh material option.

Steps to reproduce

  1. Create simple scene with viewport and 2D control node
  2. Disable 3D in viewport
  3. Use viewport as texture for material

Minimal reproduction project

ViewportTexture66247.zip

grafik

@Rindbee
Copy link
Contributor

Rindbee commented Mar 21, 2023

If the node tree doesn't nest multiple SubViewports, just enabling resource_local_to_scene on all resources will work, although it will produce a lot of errors.

Like in the MRP provided by @baschermann, enable resource_local_to_scene on the mesh resource in the MeshMaterial node.

2

Similar issues also include #68088, #72616, #74589.

If nested SubViewports are used, such as #74331 , the above solution may not work.

@baschermann
Copy link

baschermann commented Mar 25, 2023

As a workaround, set the viewport texture in the parent node of both the SubViewport and the MeshInstance3D in code:

Example in C#

public override void _Ready()
{
      RenderingServer.FramePostDraw += OnFramePostDraw;
}

private void OnFramePostDraw()
{
      SubViewport subViewport = GetNode<SubViewport>("SubViewport");
      var viewportTexture = subViewport.GetTexture();

      MeshInstance3D meshInstance = GetNode<MeshInstance3D>("Mesh");

      StandardMaterial3D mat = new()
      {
          AlbedoTexture = viewportTexture
      };

      meshInstance.SetSurfaceOverrideMaterial(0, mat);

      RenderingServer.FramePostDraw -= OnFramePostDraw;
}

@michasng
Copy link

michasng commented Apr 22, 2023

What seems to be happening is that this depends on the order of initialization. For me, the mesh was initialized first and it holds a reference to the uninitialized viewport. That issue resolves itself after a frame or so.
As mentioned, one workaround is to remove the viewport texture in the scene tree and create it programmatically.

@Rindbee
Copy link
Contributor

Rindbee commented Apr 22, 2023

What seems to be happening is that this depends on the order of initialization.

This has little to do with the order of instantiation. It mainly depends on whether ViewportTexture::setup_local_to_scene() is called and when it is called.

Currently, even if a resource has local_to_scene enabled, but its parent resource does not have local_to_scene enabled, the resource will not call setup_local_to_scene().

@clemens-tolboom
Copy link

I followed along with the 3D https://docs.godotengine.org/en/stable/tutorials/animation/playing_videos.html#displaying-a-video-on-a-3d-surface on 4.0.3.rc1 ... my video plays well but errors when running from editor gives:

E 0:00:00:0580   get_width: Viewport Texture must be set to use it.
  <C++ Error>    Condition "!vp" is true. Returning: 0
  <C++ Source>   scene/main/viewport.cpp:111 @ get_width()

E 0:00:00:0580   get_height: Viewport Texture must be set to use it.
  <C++ Error>    Condition "!vp" is true. Returning: 0
  <C++ Source>   scene/main/viewport.cpp:116 @ get_height()

E 0:00:00:0623   setup_local_to_scene: Condition "proxy.is_valid()" is true.
  <C++ Source>   scene/main/viewport.cpp:89 @ setup_local_to_scene()

@ttencate
Copy link
Contributor

Fixed by #75751?

@akien-mga akien-mga added this to the 4.1 milestone May 12, 2023
@akien-mga
Copy link
Member

Fixed by #75751?

That's likely. Please test in 4.1 dev 2 or the upcoming 4.0.3 RC 2.

@Withaust
Copy link
Contributor

4.1 dev 2 still has the issue with get_height() and get_width()
image
Project.zip

@Calinou Calinou reopened this May 15, 2023
@Withaust
Copy link
Contributor

Withaust commented May 15, 2023

Also, reopening the project attached above in 4.1 dev 2 greets you with Viewport Texture must be set to use it., so it is not fixed at all
image

@Rindbee
Copy link
Contributor

Rindbee commented May 16, 2023

Resources are instantiated before nodes during scene instantiation. At this point get_local_scene() returns null. vp_pending is not switching to true as expected.

if (get_local_scene() && !path.is_empty()) {
setup_local_to_scene();
} else {
emit_changed();
}

These error messages are printed when setting the material's texture.

RS::get_singleton()->material_set_param(_get_material(), shader_names->albedo_texture_size,
Vector2i(p_texture->get_width(), p_texture->get_height()));

@canb227
Copy link

canb227 commented May 17, 2023

Can confirm that this is still an issue in 4.1 dev 2.

@RichardR01
Copy link

RichardR01 commented May 18, 2023

This is still an issue in 4.02 stable. Having multiple errors, even though it technically works. In my case, the explosion scene is preloaded on start. It is instantiated in code. Though that doesn't make any difference. I put a camera in the explosion scene, and get the same errors when I run the scene itself.
Edit: please fix this issue. or give us something new that can do a similar thing in 3D (animated sprite texture on a 3d mesh imported).
10_viewport_errors

@kesocos
Copy link

kesocos commented Jul 15, 2023

Getting the same error on 4.1 stable

@fire
Copy link
Member

fire commented Jul 23, 2023

I hasty un-merged this in our fork. https://github.com/V-Sekai/godot/tree/viewport-path-update-fix.

The screen is pink and after the fix it works as it did in 4.0.

In 4.1 and 4.2 the screen is pink and the desktop copy of the vr viewport does not work. It's a blocker for us, so this is rush job fix.

@kapaseker
Copy link

Same Error 4.1.1

@PITR-DEV
Copy link

Still present for me in 4.2 dev5

image

@SlashScreen
Copy link
Contributor

regarding the workaround
This works in 4.1.1. Gerre's a GDScript approximation:

extends MeshInstance3D


@export var viewport:SubViewport # Could instead get a child with an @onready


func _ready() -> void:
	RenderingServer.frame_post_draw.connect(on_draw.bind())


func on_draw() -> void:
	var tex = viewport.get_texture()
	var mat = StandardMaterial3D.new()
	mat.albedo_texture = tex
	set_surface_override_material(0, mat)
	RenderingServer.frame_post_draw.disconnect(on_draw.bind())

@2fd5
Copy link

2fd5 commented Oct 18, 2023

Still present in 4.2 beta 1

@chrisl8
Copy link
Contributor

chrisl8 commented Oct 26, 2023

I built Godot from source using master today and I still get the error, so even in 4.2 Beta 3+
image

It all works fine in game though, so I guess it is a timing issue?

I will try some of the workarounds, as the error is distracting when I'm looking for real problems.

@mdarius31
Copy link

Are there plans to backport the fix to godot lts?

@Calinou
Copy link
Member

Calinou commented Nov 12, 2023

Are there plans to backport the fix to godot lts?

The issue isn't fully resolved in 4.x yet as per the above comments, so that needs to be done first before it can be backported to 3.x.

@nicemicro
Copy link

The issue isn't fuilly resolved in 4.x yet as per the above comments, so that needs to be done first before it can be backported to 3.x.

Thank you! I confirm that a similar issue exists in 3.5.3.

@YuriSizov YuriSizov modified the milestones: 4.2, 4.3 Nov 15, 2023
@SoapSpangledGames
Copy link

SoapSpangledGames commented Mar 6, 2024

I found the solution here: #55471

I set the SubViewport update mode to always to fix the problem. It seems there's a bug with "update only when visible" option and it has not been fixed yet

My SubViewport update mode is set to Always, and I still get the error message when trying to duplicate the texture. I get no error when debugging in the editor, but it happens in the exported program (in my case, the Quest 3).

I'm using Godot 4.2 stable.

@SrColoma
Copy link

I found a solution while attempting to bypass that check, and it seems to be working fine. I want to recreate Prey's screens, and this is how it's turning out:

https://twitter.com/GalacticLake/status/1769937516889616637

Before, I was getting pink screens every time I started the project. This is my solution:
image

It seems the trick lies in creating an exported variable that stores a packed scene of what the subviewport will display. Inside the _ready function, assign it as a child of the subviewport, then make the necessary configurations, such as assigning the material and calling setup_local_to_scene(). Disabling the process mode isn't necessary; that's part of my multi-screen system. With this method, I no longer encounter errors because it's created and configured after the nodes are ready.

In the editor, the screens won't be visible, but they will appear in the game; that's the only issue.
image
image

@GeorgeS2019
Copy link

GeorgeS2019 commented Mar 28, 2024

A demo to test the latest status of the Viewport in Godot4

Godot_v4 2 1-stable_mono_win64_JGIm0l0Sk4
MASSHUU12/godot-control-3d#3

@chrisl8
Copy link
Contributor

chrisl8 commented Apr 8, 2024

FWIW, the error, Viewport Texture must be set to use it. occurs in

  • v4.2.stable.official [46dc277] (4.2.1 Stable release)
    and
  • v4.3.dev.custom_build [9d6bdbc] (latest build from Master at the moment)

When running the following Godot Demo projects:

Procedural Materials
GUI in 3D

So both of those demo projects can be used to test fixes for this issue in current and future versions.

@timkrief
Copy link

I'm using 4.2.2, my project is working fine but I have those issues, should we just ignore those warnings and errors for the time being?
image

@Calinou
Copy link
Member

Calinou commented Aug 15, 2024

I'm using 4.2.2, my project is working fine but I have those issues, should we just ignore those warnings and errors for the time being?

Yes, I'd just ignore these for now.

@Withaust
Copy link
Contributor

4.3 stable, still happening :(

@NervenCid
Copy link

I am using the 4.3 stable version, but i get the same error:

This is the structure of my nodes:

image

And i am defining the HUD as my texture on "MeshInstance3D" but i get the same errors:

image

How can i set a texture of a viewport? I can't see the option

@nkalpakis21

This comment was marked as off-topic.

@AThousandShips
Copy link
Member

Please see the thread above for an explanation, but please don't bump issues without adding significant new information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.