Skip to content

fix: Address bugs in multiplayer-fps example#597

Open
krazyjakee wants to merge 1 commit into
foxssake:mainfrom
krazyjakee:fix/multiplayer-fps-example-bugs
Open

fix: Address bugs in multiplayer-fps example#597
krazyjakee wants to merge 1 commit into
foxssake:mainfrom
krazyjakee:fix/multiplayer-fps-example-bugs

Conversation

@krazyjakee
Copy link
Copy Markdown
Contributor

Summary

Four small bugfixes uncovered while reviewing the examples/multiplayer-fps scripts:

  • node-pool.gdnode.is_instance_valid() is invalid; is_instance_valid is a global function. Calling clear() would raise. Changed to is_instance_valid(node).
  • player.gd — death sound, deaths counter, and die() were fired on every tick while health <= 0, so they multi-triggered between damage and respawn (worst on non-authority peers where die() early-returns). Now fires once on the alive → dead transition via a local _was_alive flag.
  • player-input.gd_notification(NOTIFICATION_WM_WINDOW_FOCUS_IN) ran on every player's Input node in the local tree, so window refocus called Input.set_mouse_mode(CAPTURED) once per remote player and cleared override_mouse on Inputs the local peer doesn't own. Now early-returns for non-authority Input nodes.
  • bullethole.gd — replaced the hardcoded get_tree().root.get_node("multiplayer-fps/Map/StaticBody3D") lookup with an @export var spawn_root: Node, falling back to get_tree().current_scene. The example keeps working without scene edits and the component is reusable elsewhere.

Test plan

  • Open examples/multiplayer-fps/multiplayer-fps.tscn and host a local server
  • Connect a second client; confirm each player still spawns at a deterministic spawn point
  • Shoot the other player to zero health; confirm the death sound plays exactly once per death and deaths increments by 1
  • Alt-tab away from and back to the game window with two clients running; confirm only the local player's mouse is recaptured and remote Input nodes are unaffected
  • Confirm bullet hole decals still spawn on the map geometry

- node-pool: call is_instance_valid() as global function, not method
- player: fire death sound and increment deaths only on alive -> dead
  transition, so they don't multi-trigger while health stays <= 0
- player-input: gate _notification on multiplayer authority so window
  focus doesn't fan out to every remote player's Input node
- bullethole: replace hardcoded scene path with an exported spawn_root
  Node, falling back to the current scene
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant