How to render multiple sub viewports to multiple viewport textures

Godot Version

v4.2.2.stable.mono.official

Question

I am attempting to render 3D elements inside of a 2D UI. Here’s my current setup:

I have an InvetorySlot scene with the following layout:

inventory-slot

My intent here is for the texture rect to show a 3D model, which is added to the ItemAnchor node within the SubViewport. The TextureRect has a SubviewportTexture which is linked to the SubViewport in the scene, and is also marked as “Local to Scene”:

Then, one level up I have a Invetory scene, with 10 of these InvetoryItems as children:

The result should be a 10 item inventory, each slot with distinct renders / textures. This almost works. However, when I add an item to one of the slots, all slots show the same texture:

Looking at the scene tree, the item is added to only the expected slot, and each ViewportTexture seems to be a unique instance:

I for the life of me cannot figure out why these textures always end up being the same! I’ve tried various hacks of trying to duplicate the textures in code, but get a pink box whenever doing that. Does anyone have any advice?

All images here due to new user embed limit: Godot SubViewport Debugging - Album on Imgur

Figured it out! I thought each instance of the SubViewport would act as a unique scene, but that is not the case. All of the textures were in fact unique, but they were all being generated looking at the same object in world space! By giving each 3D scene an offset (that is far away from the main play area), the rendering now works :slight_smile:

workinginventory

i discovered there is a own world 3d option in the subviewport node that only renders the 3d nodes that are children to the node.