The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hey Godoters,

I'm currently working on a small project that I'm trying to add multiplayer functionality to. For some reason, when a second player joins the server, all of the variables on each person's player nodes reverts to null. I have all the basic functionality working, the two instances of the game both run independently and both players can see each other moving independently of each other, so there's no problems there. The game is 3D and kind of like an RTS where players spawn units that they send down a central lane to attack each other.

example one:
I have two string variables on the player scene: Current Team and Opponent Team
When the first player (host) joins, a player scene is added to the tree, the peer is given authority over it, and their current team now becomes "Blue" and opponent team becomes "Red", when a second player (client) connects, the same thing happens but their current team becomes "Red", opponent is "Blue". I use strings to make signal calls depending on which team is executing an action. However, once the second player joins, their current and opponent teams are set correctly and then immediately all players get null values for their variables.

example two:

On the player scene, I have a linked scene called "Placer" which handles the unit UI menu and placing a selected unit in the world based on where the player's mouse is. When the player scene is in ready(), it passes a reference of itself to the placer scene so that the placer can get reference to the player's mouse location in world space which is calculated in a function within the player script and stored in a variable. When an instance of the game hosts, the player is able to spawn in units as normal. When a client joins the server, the client is able to spawn in units, but when the host tries to spawn in units, the variable that stores the player's mouse position becomes null.

Is there something I'm missing with regards to multiplayer set up? I can provide more information if necessary. I've tried using the multiplayer synchronizer on the player scene to sync the mouse location variable and the team variables but this doesn't seem to work.

Godot version 4.1
in Engine by (14 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.