Skip to content

Conversation

TuysuzTavsan
Copy link

Reopened this pull request to its own branch.

Real life use case:
Imagine a fully server authoritative game. There are static nodes on the world which does not need constant updates with any synchronizer node. We may want some of these static nodes to have initial values such as global_transform, custom timers, any custom property. We may want to control spawn/despawn logic per peer to prevent vision hacks. We dont want to maintain custom serializable data structs or assignments just to initialize some values on scenes.

Problems:

  • Godots built in MultiplayerSpawner does not have any visibility settings on its own, instead it relies on MultiplayerSyncronizers visibility configuration.
  • Godots built in MultiplayerSpawner does not have functionality to despawn on remote peers.
  • Godots built in MultiplayerSpawner have ability to spawn remote scene with parameters, but its usage is impractical.
  • Even when MultiplayerSpawner is used together with MultiplayerSyncronizer, custom spawn() function requires writing code and maintaining data structs.
  • Its hard to understand MultiplayerSpawners documentation, it leads to unexpected behaviors and wasted valuable development time.
  • I really liked the workflow of changing properties on editor with :some_node:some_property fashion. Proposed spawner node will have the same style and therefore improve the workflow.
  • Spawning logic should be separated from other nodes let alone godots MultiplayerSyncronizer.
  • Godots multiplayer nodes need new features or rework on some areas, which having a custom spawner node on netfox add on will benefit the project on the long run. We will have features and we wont have to rely on MultiplayerSpawner.

Implementation:

  • 1 new helper node which named SceneSpawner. Which has ability to spawn/despawn scene on remote peer/s with initialized values.
  • 1 new singleton node to receive scene spawn/despawn reliable rpcs on the client side named NetworkSceneSpawner.

SceneSpawner:
This node is designed to use on host application.
Usage

  1. Add it as child of the scene you want to spawn/despawn.
  2. Select root node
  3. Add properties with :property or :some_node:some_property fashion.
  4. Select flags (Replicate on spawn) (Replicate on despawn) to choose desired behavior.
    Replicate on spawn -> If true will broadcast scene spawn on all peers.
    Replicate on despawn -> If true will broadcast scene despawn on all peers.
  5. Select current scene_path e.g res://scenes/mine.tscn

Notes: To allow spawning/despawning on specific peers SceneSpawner exposes 2 functions.
1- spawn_on_peer
2- despawn_on_peer
SceneSpawner will automatically despawn scene from instantiated remote peers by keeping internal list of them as well since this is the desired behavior for most games.

NetworkSceneSpawner:
This singleton listens despawn / spawn rpcs.

Notes: Loading scenes on runtime frequently is not good for performance reasons therefore singleton exposes set_preloaded_scenes(scenes : Array[PackedScene]) function. Scenes can be loaded when the game started or preloaded and passed to the singleton to avoid drops in the frame rate.

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