#Procedural generation
1 messages · Page 1 of 1 (latest)
so that's the code that generates the tilemap :
fuck, too long

you can judge that ugly ass code
i basically need the host to call the ClientRpc when i am sure the Objects have been spawned on the network, and received by the client
which i thought i was already doing
but network delay is fucking me over
You can use objectsSpawnedServer by sending it to all the clients
Then have a script on the client side that tracks objectsSpawnedClient
each spawnable prefab will have a script on it that increments objectsSpawnedClient
when objectsSpawnedClient == objectsSpawnedServer you send a ServerRpc from the client to tell the server to call the ClientRpc you want called
It's not the most elegant thing, but it seems like you don't have much time for anything else
you're right about that
so, how can i implement that ? i need to make those 2 variables NetworkVariables right ? else the client won't be able to get them
I would just make them normal variables and update them through Rpcs tbh
you do objectsSpawnedServer++ anytime you instantiate on the Host, and when you're done call a ClientRpc to send the value to all clients
but the object itself would be a networkObject right ?
what object?
idk i think i got confused
this is the code that instantiates Objects inside rooms:
( yet again, this is a mess )
Rooms themselves are instantiated with almost the same code but it's a different script
What if I simply check inside the TileMap placing script if I have 2 players
And if so, I call the Rpc
I could still have timing issues
But probably less
Since I'll only be calling the Rpc when the client has joined the new scene, from the host's perspective
That should give enough time for the objects to spawn across the network, right?
Again shitty fix but could that work ?
I'm not sure what you mean or how that would help with timing issues.
The problem is that the ClientRpc is called too early, client side
I think I got confused on the way Rpc work
If I want the client to call the Rpc on his side
I have to get his gameobject and call the clientRpc right
This way it'll execute on his gameObject, client side
I don't even know how what I was doing was working before
I was only calling the Rpc on the host
How tf did it end up called client side
😂
Whatever NetworkBehaviour you're calling a ClientRpc in it should be called for the Host only. When you make this call, the Host sends a message to all clients to run the function.
But if I only call the Rpc on the host, it won't run on the client ?
I'm talking about the host player gameObject
That's literally the purpose of a ClientRpc.
Then there's something I'm not getting
The host is both a server and a client
Si if the host calls a ClientRpc on his own gameObject, it should only get executed on his side, no?
He's not a client client side right?
You're making a networking call. The purpose is to send a message across the network. If you want it to only run on one side, why are you making a networking call?
I don't that's the point
I want the host to call the ClientRpc on the Other player gameObject
So that it gets executed on his side
So basically if I have a script called SpawnTiles with a ClientRpc function, I need to get his object and get the component SpawnTiles and call the ClientRpc right?
Called host side, executed client side on the client gameObject
That's how Rpc works no?
Or am I losing my mind
What does "get his object" mean
With a function like gameObject.Findgameobjectswithtag and filtering based on islocalPlayer
I know extremely inefficient
Does does that have to do with calling an RPC on a script called SpawnTiles?
Yeah, I simply want the host to call the Rpc so that the client executes the function on His gameObject and on his side
Again, no idea what "his gameobject" means
Well, in multiplayer there will be 2 gameObjets right
The host and the client
The 2 players
two Player Objects.. you can have multiple other NetworkObjects capable of calling RPCs.
You don't need the player object to call an RPC on a script that's a NetworkBehaviour and has nothing to do with the player
Then there's something I'm not getting about how RPCs work
ðŸ˜
I simply want the function to execute client side
Which I am doing rn but I don't even know how
Since I only call it host side ?
I only call it when IsHost is true
Is it true even client side ?
If you have a script that's a
NetworkBehaviour
it can call RPCs like ClientRpc (which sends a message from the server to all clients) and ServerRpc (which sends a message from one client to the server).
You can check IsHost or IsClient on ANY NetworkBehaviour.
You can use IsHost to make a check to ensure you're the server and call a ClientRpc to run a function on ALL clients.
But let me get that straight
Client-Side, which gameobject is running the Rpc ?
The same object the Rpc has been called from right?
Yes
Just client side instead of server side
So if the host calls a clientRpc, nothing happens for the other player right ? Since the host is it's own client
If I have a function
[ClientRpc]
private void FunctionToRunOnAllClients()
and I make this call:
if (IsHost)
FunctionToRunOnAllClients();
FunctionToRunOnAllClients()
runs on every single client, including the Host because the Host is also a client.
So if I make a gameobject which only contains that Rpc, and the calls that function from the host, it should execute on all instances of that gameobject throughout the network
Exactly
Damn
I don't know what I believed rpcs were
But it was something else
Insane confusion
Simply is just a message to all clients that have an instance of that NetworkBehaviour
For that to work, I do need to spawn the object right?
I can't juste drop it in the hierarchy
And expect it to work
NetworkObjects placed within the hierarchy have .Spawn() called on them as soon as the client connects
Oh
That's good to know
But then the gameobject will exist in double right? Or wait no since clients can't spawn objects unless calling a serverRpc
No doubles, don't overthink things lol
I'm just stressed out and tired xD
I just meant if you place it in the hierarchy, all the necessary network setup for the networkobject gets done automatically when you connect
meaning you don't have to do anything for it to work
I believe NetworkObjects are also disabled until a connection is made as well
as a safeguard
So basically
I'm creating an object that holds the clientRpc
And I'm calling that rpc from the Host once everything is spawned
That should work right ?
Well it's working locally
Time to test
Begging for it to work
😂
🤞
If it was that simple I'm probably gonna end myself iswtg
😂
I think what I was doing was calling the Rpc on the host
Which would explain why I had timing issues
I'm not sure what you mean but the Host is where you're supposed to call ClientRpcs lol
I mean the host was the one holding the rpc
So it was the host gameObject executing the tile placement on the client
Which I didn't want
Okay now it works a bit better, the Rpc is just called a little bit too early in my third level
Maybe a dumb question, but if I call a ClientRpc, it will execute faster host side than client side right? Or same speed
You can use [RPC(DeferLocal=true)] to delay it a frame. But it will still take network travel time before it will run on the remote clients
https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/message-system/rpc/#other-rpc-parameters
Any process can communicate with any other process by sending a remote procedure call (RPC). As of Netcode for GameObjects version 1.8.0, the Rpc attribute encompasses server to client RPCs, client to server RPCs, and client to client RPCs. The Rpc attribute is session-mode agnostic and can be used in both client-server and distributed authority...
I need to actually defer it on the client side
I can check if a ClientRpc is executing host side right?
With a simple if (IsHost)
I think I'm just gonna defer the generation in the level 3 by 0.5 seconds
For the non-hosts
This should fix the issue where the tileMap is spawned before the objects are destroyed properly
Well technically I can just defer both the generation and the teleportation to the spawnPoint by 1 second for the client
Might be a dumb question, but how can I reset the "multiplayer state" after leaving the multiplayer scene ? Do I have to manually close the relay ?
I have a bug where after returning to the main scene, if the hosts didn't and does alt+F4 for example, it completely destroys the game for the client even though he isn't in a multiplayer scene anymore, I'm suspecting he's still connected to the relay in a way
If you shutdown the server any NetworkObjects will be destroyed for all clients
Disabled actually, not destroyed
You should be disconnecting from the server if a client goes back to the main menu regardless
yeah but it really makes my game bug
since it destroys the playerGameObject
i'll have to handle it someway
network objects will get destroyed when the network disconnects
How can I make it so that when that happens the client goes back to another scene?
Is there a onNetworkdestroy callback ?
Or event
NetworkManager.OnClientDisconnectCallback
that gets invoked at the instant the client gets disconnected right ?
Yes
For the local client and the server
So you’ll need some check in there to make sure it’s for the client who disconnected and not for the server
Or else anytime someone disconnects the server will go back to main menu as well
There’s also NetworkManager.OnClientStopped
Can I invoke networkManager.singleton.shutdown and destroy the Network manager.singleton.gameobject when invoking that callback?
That's not a problem, the multiplayer is made to only work if 2 people are constantly connected
If not everyone should go back to the main menu
Can you have more than 2 players?
Then yeah you just can just load the main menu OnClientDisconnectCallback
Will handle the host and the client for both situations:
- host leaving
- client leaving
Pretty sure all NGO requires of you is to call NetworkManager.Shutdown
Any other cleanup would be dependent on your game
But it doesn’t seem like you’d need any from what I know, it seems like you want everything fully reset as brand new anyway
Yeah
Network Manager is set to Do Not Destroy on Load. So if your main menu had a network manager, you would end up with 2 managers
NGOs NetworkManager Singleton doesn’t destroy repeat instances on its own?