scatter
scatter copied to clipboard
Add option for basic multiplayer sync
(needed this for a project so figured I'd PR in case this is something you want :) )
Adds a new "Multiplayer Sync" option (false by default) on ProtonScatter node, which if enabled will sync the scatter output transforms from the multiplayer authority to clients
More specifically calls to these functions are synced via rpc:
-
_clear_collision_data
-
clear_output
-
_on_transforms_ready
Tested in Godot 4.1.1 (in an unreleased project) Might be worth making a dedicated test setup, idk how thorough you want to be
Demo (left is server with enabled
field being toggled, right is client):
https://github.com/HungryProton/scatter/assets/13819558/b2b1e5af-ee76-4653-88f3-6f5c7cd5bc70
Some notes:
- I'm not particularly familiar with this addon's code so not sure if there's other things that might cause issues with this
- When using this you probably want to set
enabled
to false on clients, otherwise they will also try to scatter locally.- (it'd be possible to make it so clients ignore
enabled
/rebuild
/etc if multiplayer sync is on, if that's desired)
- (it'd be possible to make it so clients ignore
- The
_multiplayer_call
function looks kinda dumb, but I was trying to avoid usingbind
since iircrpc
only works withbind
on 4.1.1+ - Open to naming suggestions (ie.
multiplayer_sync
/"Multiplayer Sync",_multiplayer_call
,_do_transforms_ready
)
Hey, sorry for the delay. I don't know if scatter is really supposed to handle multiplayer at all. As long as you use the same seed on both sides, the results should be identical. (If they're not, that's an issue I need to fix)
I'm not familiar with multiplayer, but if you really need to drive it from the network, I would make it a separate node. (Added under a ScatterNode, like the ScatterItem nodes):
- On the server side, the multiplayer node would listen to its parent
build_complete
signal, and send the transform list to the client - The client side receives the transforms from the server, and calls
clear_output
and_on_transform_ready
on the scatter node. (similar to whatScatterCache
does)
Basically, moving the multiplayer_call method to its own node, along with all the multiplayer features. Makes it easier to maintain (the scatter nodes don't know about multiplayer but still work as usual) and it doesn't cause conflicts with future updates.