godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.36k stars 20.01k forks source link

multiplayer.is_server() returns true by default #92066

Open dev-cyprium opened 3 months ago

dev-cyprium commented 3 months ago

Tested versions

System information

Godot v4.2.2.stable - Windows 10.0.22631 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 3070 (NVIDIA; 31.0.15.5244) - AMD Ryzen 7 3700X 8-Core Processor (16 Threads)

Issue description

multiplayer.is_server() returns true in a fresh project. It's not stated like that in the documentation.

Steps to reproduce

Minimal reproduction project (MRP)

TEst.zip TEst.zip

dev-cyprium commented 3 months ago

The use case was in my actual project I have this logic:

func _ready():
    GuiSignalManager.role_selected.connect(_on_role_selected)
    GuiSignalManager.role_changed.connect(_on_role_changed)
    margin_container_pane.hide()
    Console.attach(self)

    if multiplayer.is_server():
        Console.write_line("WINDOW IS SERVER!! menu.gd:25")
        host_options.visible = true

The host_options are visible for both the server and the client, so I was wondering if this should be false initially?

Summersay415 commented 3 months ago

This is intended behaviour. Default multiplayer peer is OfflineMultiplayerPeer, which mimics server. You can set multiplayer.multiplayer_peer to null to get error instead.

AThousandShips commented 3 months ago

This is documented here but should probably be mentioned elsewhere as well