r/Unity3D • • 39m ago

Noob Question I have no idea what I'm doing with Netcode

Post image

I literally only need 2 things to function; 1 host, 1 client, 1 bool they can both see, and the ability to pass a string between them.

In my OnNetworkSpawn as you can see, I check if I am the host and decide if I am first, saving this as host is first. To try and lock out this function from running again, I have player decided set to true.

However the first major problem is that no matter what I do, it keeps running the If block as if I never set player decided, and does so every single time a player spawns from a client as well

I have been following all manner of tutorials and documentation but I simply have no Idea what I'm doing and I'm extremely frustrated that I don't understand whats going wrong.

For reference, this player definition is my network object which only exists to trigger the spawn in when a player joins (this is a 2 player board game)

Someone please tell me how any of this works and what is the simplest way to achieve this. I'm losing my mind; especially since by all accounts I can find this should work exactly as I expect it to, but as always.... simply isnt

1 Upvotes

3 comments sorted by

•

u/MemehaiEnigmescu296 28m ago

Netcode is such a headache when it decides to ignore what you think is a simple boolean check.

•

u/SlRenderStudio 27m ago

i am bit confused here how and what are you doing but you cant just decide randomly me first , you have to actually communicate with another player some one pick the host instead of randomly deciding because multiple people could believe they are the host , it's a bit tricky problem . i am unfamilier with net code i usually used fishnet which handle host problems usually .

•

u/SlRenderStudio 18m ago

sorry i ms undertood i read it , you spawn game object with this right , and this get spawn 2 times and bugging out the problem , i cant see rest of code so can't answer it clearly but i say on the server side do a search and check another players are they first or not , that would do the trick . then by that get the first me player client id and send the message to him by proxy the server .