Repository: godot
Issue: Unpredictable behavior from ViewportTexture and SubViewport as children of a Sprite3D
Labels: topic:rendering,needs testing

### Godot version

Godot v4.2.beta1

### System information

Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4090 (NVIDIA; 31.0.15.3598) - 13th Gen Intel(R) Core(TM) i9-13900K (32 Threads)

### Issue description

I have a scene which creates a floating 2D health bar billboarded above a 3D character. It is constructed like so:

HealthBar.tscn
```
[gd_scene load_steps=3 format=3 uid="uid://1xiljqtigxx2"]

[ext_resource type="Script" path="res://scripts/HealthBar.gd" id="1_bo2ko"]

[sub_resource type="ViewportTexture" id="ViewportTexture_y2dik"]
viewport_path = NodePath("SubViewport")

[node name="HealthBar" type="Sprite3D"]
transform = Transform3D(0.33, 0, 0, 0, 0.33, 0, 0, 0, 0.33, 0, 3, 0)
layers = 16
billboard = 1
texture = SubResource("ViewportTexture_y2dik")
script = ExtResource("1_bo2ko")

[node name="SubViewport" type="SubViewport" parent="."]
disable_3d = true
transparent_bg = true
handle_input_locally = false
gui_disable_input = true
size = Vector2i(256, 64)

[node name="CanvasLayer" type="CanvasLayer" parent="SubViewport"]

[node name="Polygon2D" type="Polygon2D" parent="SubViewport/CanvasLayer"]
color = Color(1, 1, 1, 0.784314)
polygon = PackedVector2Array(0, 8, 8, 0, 248, 0, 256, 8, 256, 56, 248, 64, 8, 64, 0, 56)

[node name="HealthBar" type="Polygon2D" parent="SubViewport/CanvasLayer"]
position = Vector2(8, 8)
color = Color(1, 0, 0, 0.784314)
polygon = PackedVector2Array(0, 4, 4, 0, 236, 0, 240, 4, 240, 44, 236, 48, 4, 48, 0, 44)
```

HealthBar.gd
```GDScript
extends Sprite3D
class_name HealthBar

@export var hide_on_no_damaged := false

# red polygon
@onready var health_bar := $"SubViewport/CanvasLayer/HealthBar"

func _ready():
	if hide_on_no_damaged:
		visible = false

func set_health(percent: float):
	if hide_on_no_damaged and percent <= 0 or percent >= 1:
		visible = false
	else:
		visible = true
	health_bar.set_scale(Vector2(clamp(percent, 0,1), 1.0))
	health_bar.queue_redraw()

```

When attached to `CharacterBody3D` in the main scene I see the following clue in the console.

>  Path to node is invalid: 'SubViewport'.
  scene/main/viewport.cpp:147 - Viewport Texture must be set to use it.
  scene/main/viewport.cpp:169 - Viewport Texture must be set to use it.
  
 However, I do not see the `Sprite3D` rendered above the character in the editor. At runtime sometimes I will see the sprite rendered above the character and some times I will not. If I drop a second character (an enemy, for example) into the main scene, only one of them will render.

### Steps to reproduce

Unfortunately, I haven't been able to reduce the problem to a simple set of reproducible steps. It doesn't reproduce in isolation. If someone familiar with the `SubViewport` code has any insight into what I could look into next that would be helpful.

I suspect  it is related to the `SubViewport` instancing inside the `Sprite3D` which is then using the target `ViewportTexture`. The intermittent behavior is what has me confused.

### Minimal reproduction project

N/A