#Procedural generation

1 messages · Page 1 of 1 (latest)

bright trail
#

I guess drop your code here and we can take a look at it

forest lichen
#

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

slow zinc
#

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

forest lichen
#

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

slow zinc
#

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

forest lichen
#

but the object itself would be a networkObject right ?

slow zinc
#

what object?

forest lichen
#

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 ?

slow zinc
#

I'm not sure what you mean or how that would help with timing issues.

forest lichen
#

The problem is that the ClientRpc is called too early, client side

slow zinc
#

I'm aware

#

I would just go with your WaitForSeconds fix tbh

forest lichen
#

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

#

😂

slow zinc
#

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.

forest lichen
#

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

slow zinc
#

That's literally the purpose of a ClientRpc.

forest lichen
#

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?

slow zinc
#

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?

forest lichen
#

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

slow zinc
#

What does "get his object" mean

forest lichen
#

With a function like gameObject.Findgameobjectswithtag and filtering based on islocalPlayer

#

I know extremely inefficient

slow zinc
#

Does does that have to do with calling an RPC on a script called SpawnTiles?

forest lichen
#

Yeah, I simply want the host to call the Rpc so that the client executes the function on His gameObject and on his side

slow zinc
#

Again, no idea what "his gameobject" means

forest lichen
#

Well, in multiplayer there will be 2 gameObjets right

#

The host and the client

#

The 2 players

slow zinc
#

two Player Objects.. you can have multiple other NetworkObjects capable of calling RPCs.

forest lichen
#

The object spawned by the network manager

#

Basically

slow zinc
#

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

forest lichen
#

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 ?

slow zinc
#

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.

forest lichen
#

But let me get that straight

Client-Side, which gameobject is running the Rpc ?

#

The same object the Rpc has been called from right?

slow zinc
#

Yes

forest lichen
#

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

slow zinc
#

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.

forest lichen
#

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

slow zinc
#

Exactly

forest lichen
#

Damn

#

I don't know what I believed rpcs were

#

But it was something else

#

Insane confusion

slow zinc
#

Simply is just a message to all clients that have an instance of that NetworkBehaviour

forest lichen
#

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

slow zinc
#

NetworkObjects placed within the hierarchy have .Spawn() called on them as soon as the client connects

forest lichen
#

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

slow zinc
#

No doubles, don't overthink things lol

forest lichen
#

I'm just stressed out and tired xD

slow zinc
#

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

forest lichen
#

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

#

😂

slow zinc
#

🤞

forest lichen
#

If it was that simple I'm probably gonna end myself iswtg

slow zinc
#

😂

forest lichen
#

I think what I was doing was calling the Rpc on the host

#

Which would explain why I had timing issues

slow zinc
#

I'm not sure what you mean but the Host is where you're supposed to call ClientRpcs lol

forest lichen
#

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

bright trail
#

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...

forest lichen
#

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

forest lichen
#

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

slow zinc
#

If you shutdown the server any NetworkObjects will be destroyed for all clients

#

Disabled actually, not destroyed

slow zinc
forest lichen
#

yeah but it really makes my game bug

#

since it destroys the playerGameObject

#

i'll have to handle it someway

bright trail
forest lichen
#

How can I make it so that when that happens the client goes back to another scene?

#

Is there a onNetworkdestroy callback ?

#

Or event

bright trail
forest lichen
slow zinc
#

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

forest lichen
#

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

slow zinc
#

Can you have more than 2 players?

forest lichen
#

Nop

#

Just 2

#

The lobby is set to have 2 players max

slow zinc
#

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
forest lichen
#

Nice

#

Is there a proper way to reset everything when invoking that callback?

slow zinc
#

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

forest lichen
#

Yeah

bright trail
#

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

slow zinc
#

NGOs NetworkManager Singleton doesn’t destroy repeat instances on its own?

forest lichen
#

Nop, i have to manually destroy it

#

What I did is on the callback, shutdown the NetworkManager, then destroy it, then returning null