Multiple objects using viewports as textures shares the same viewport

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By deps

Hi,

I’m having a bit of a problem using multiple objects that uses viewports as textures.

I can see in the debug output that the scripts are running independently and updating the “screens” randomly but in the game it seems they all use the same texture from a single viewport because the texture is updated exactly at the same time on all the screens (Debug output in linked image is seconds until next update on the different screens). (Link to picture illustrating the problem)

Some notes and stuff I tried already:

I have enabled “Local to Scene” on both Node2D and the CRT scripts, but it appears to not solve this problem.

If I print() the viewport object from line 7 or the cube object from line 13 it seems like they are indeed different objects, since they get different names:

[Spatial:1229]: [Viewport:1232]
[Spatial:1229]: [MeshInstance:1230]
[Spatial:1239]: [Viewport:1242]
[Spatial:1239]: [MeshInstance:1240]
[Spatial:1249]: [Viewport:1252]
[Spatial:1249]: [MeshInstance:1250]

I created the two smaller screens by duplicating the larger one and resizing the copy if this is any clue. But as I wrote above the scripts can prove that Cube and Node2D is different on all duplicates.

It appears the Node2D object with the highest ID/Name, like [Node2D:1258], is the one that is owning the texture. I proved this by having the script where str(self)=="[Node2D:1258]" print a slightly different message, and all screens showed this.

What did I do wrong? I am using v3.0.6.stable.official downloaded from Steam.

:bust_in_silhouette: Reply From: Michal Seta

The resources are shared in Godot so you neet to make a new copy of your material:

var mat = cube.get_surface_material(0).duplicate()

or something like that.

Thanks a lot! That did it! :slight_smile:

deps | 2018-09-30 21:06