How not to render extra guns in Godot multiplayer FPS?

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

I’m trying to make an ordinary multiplayer FPS. I use a second Camera3D and a SubViewport to avoid player’s gun clipping into the wall:

Both cameras’ cull masks set up the way that everything works fine until the other player hasn’t connected.

As another player connects to a host, every player get an extra gun rendered on their screen:

Apparently it’s happening because every new connection instantiates a new player, hence there’s another viewport in the world which adds up everything it has to render to players’ screens. Also if I remove the whole SubViewportContainer, guns don’t render in the wrong places anymore, only in other players’ hands, but now they’re clipping into the walls.

Here’s my world script that handles connections:

extends Node

@onready var main_menu = $CanvasLayer/Menu
@onready var address_entry = $CanvasLayer/Menu/MarginContainer/VBoxContainer/AddressEntry

const Player = preload("res://scenes/Player.tscn")
const PORT = 8899
var enet_peer =

func _unhandled_input(event):
	if Input.is_action_just_pressed("exit"):

func _on_host_pressed():
	multiplayer.multiplayer_peer = enet_peer

func _on_join_pressed():
	enet_peer.create_client(address_entry.text, PORT)
	multiplayer.multiplayer_peer = enet_peer

func add_player(peer_id):
	var player = Player.instantiate() = str(peer_id)

This seems like a common task but still I couldn’t manage to find any Godot 4 solution on the Internet. I will be grateful if you share any advice on how to render only player’s gun on their screen and still avoid gun clipping.

The Godot project i’m working on is based on DevLogLogan’s Online Multiplayer FPS From Scratch tutorial:

Hi!, What if you put the viewport in a group and then, when you create a player, check if that viewport already exists?

   //ceate viewport

crossbito | 2023-06-06 15:23