#NetworkBehaviour spawning and despawning...
1 messages ยท Page 1 of 1 (latest)
Which makes sense why the other example Sets the intial state in OnNetworkSpawn with a "server/Authority/Owner" check
Yeah. IMO, a good majority of people should never be trying to read/write a NetworkVariable's Value before OnNetworkSpawn.
Either use a regular variable that's for offline usage or make your code that depends on the NetworkVariable only trigger through OnValueChange.
A lot of people are too used to the Awake Start Update paradigm. Networking is a different ball game and your code (IMO) should revolve around when you have received and synchronized data
Network Variables would not be updated until OnNetworkSpawn() so reading them beforehand would not be correct. They need to be registered with the network manager on the server side before being written to and that happens on spawn as well
Wait sorry. I need to do more reading now. Thank you for the help though
#archived-networking message @strange belfry
Here you said to check HasAuthority, but my Unity is saying.
error CS0103: The name 'HasAuthority' does not exist in the current context
I am not sure if it is a version thing. Here is how it is being used.
public override void OnNetworkSpawn()
{
if (HasAuthority)
{
_networkPosition.Value = Data.Position;
_networkRotation.Value = Quaternion.Euler(Data.Rotation);
_networkScale.Value = Data.Scale;
_networkColor.Value = Data.Color;
_networkIsSolarSystem.Value = Data.IsSolarSystem;
}
// TODO Not sure if owner should subscribe, or maybe ignore the event in the handler of it changed?
// Sync local state for any network changes
_networkPosition.OnValueChanged += Handle_NetworkPosition_OnValueChanged;
_networkRotation.OnValueChanged += Handle_NetworkRotation_OnValueChanged;
_networkScale.OnValueChanged += Handle_NetworkScale_OnValueChanged;
_networkIsSolarSystem.OnValueChanged += Handle_NetworkIsSolarSystem_ValueChanged;
_networkColor.OnValueChanged += Handle_NetworkColor_OnValueChanged;
}
Should I use that differently, or would IsOwner work here instead?
Yeah, IsOwner will work for you. HasAuthority is new to 2.0.0 IIRC
You need to be in Unity 6 and using NGO2 to use Distributed Authority
Here is more detail about how authority work when using DA
https://docs-multiplayer.unity3d.com/netcode/current/basics/ownership/
By default, Netcode for GameObjects assumes a client-server topology, in which the server owns all NetworkObjects (with some exceptions) and has ultimate authority over spawning and despawning.
Could definitly be.
Will the client that spawns a NetworkObject be assigned the owner of it automatically? Or the host?
on DA?
The client.
There is no host when using DA. all clients can spawn their own objects. and yea, they will have authority over what they spawn
Okay. I remember some docs on handling late joiners, but their search is failing me.
There shouldn't be anything special you have to regarding spawning or ownership with late joiners.
Probably because the funkiness of my setup. But the Server is the default owner on a NetworkObject.Spawn(), had to do a NetworkObject.SpawnWithOwnership()
I said for DA.
Default ownership for client-server will always be the server.
Is host migration still not supported out of the box with Relay?
Not really. The best thing you can do is use Lobby to reconnect clients to a new host.
Ah, that is really bad ๐
In the sense of for me, but also as a design by Unity, though not suprising Unity would make something that bad.
Huge lag spike when the host disconects. Also looking at other issues, like the time for the host being disconnected is big.
Host Migration is a complicated topic and is often very game specific. I don't know of a networking library that has it built in.
Photon
They allow you to switch the "Master Client". That's not Host Migration. Nowhere close.
๐คท๐ปโโ๏ธ
I use Relay in production. I haven't encountered these issues.
Interesting
Okay so I was thinking that I would have to respawn the entire scene, but when the host leaves, and I assign a new host, will all the NetworkObjects in the room still be(not including if their state changed after host disconnect) in a valid state? Or at least still have the same network ID? So I just need to get a new Relay?
Outside of tons of complications of course for my custom implementation
in client server when the host leaves the entire network gets shut down. all network objects get destroyed.
With distributed authority, if the object was to set to distributable authority, then they will get transferred to the remaining clients