Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

fix: Added support for byte on NetworkVariable through codegen #2953

Closed Ufabsther closed 5 months ago

Ufabsther commented 5 months ago

the codegen wasn't picking byte - it's because a variable of a type other than NetworkVariable<byte> (such as NetworkVariable<FixedString32Bytes>) is serializing a byte value as part of its delta serialization. Delta serialization was added in NGO 1.9, which is why it doesn't happen in previous versions. This code assumes the existence of a byte serializer, but if the user doesn't have a NetworkVariable in their code, the byte serializer won't be initialized by the codegen pass.

fix: #2920

Changelog

Testing and Documentation

unity-cla-assistant commented 5 months ago

CLA assistant check
All committers have signed the CLA.

Ufabsther commented 5 months ago

@Unity-Technologies/multiplayer-sdk I'm part of Unity, could you MP a proper way to fix the CLA situation

matus-d-ui42 commented 4 months ago

hello @Ufabsther @NoelStephensUnity
im really sorry, but the fix does not work for me after upgrading to 1.10.0 :/

I do have the supposed fix in the code image

image also again if i add

NetworkVariableSerialization<byte>.AreEqual = NetworkVariableSerialization<byte>.ValueEquals;

to NetworkVariableSerialization:InitializeIntegerSerialization it starts working

should I do something extra to trigger the codegen, or is there still something wrong with the code? thanks! :)

xSkeletor commented 4 months ago

I also noticed that after upgrading to version 1.10.0 that I still continue to get the same error. But if I add the workaround that was mentioned previously ([GenerateSerializationForType(typeof(byte))]) to one of my scripts, it fixes the error.

NoelStephensUnity commented 4 months ago

We apologize for any confusion this might have caused. We are aware that this PR does not resolve the issue and have an alternate approach that will be reviewed early next week. If it gets a sign off on the different approach, then I will start a patch update to NGO v1.10.1 that will include the alternate fix.

If you are having this issue and using fixed strings, then you could update your manifest with this: "com.unity.netcode.gameobjects": "https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git?path=com.unity.netcode.gameobjects#fix/fixedstring-byte-writing-and-comparing",

And report back here if that resolves your issue.

LightPat commented 3 months ago

We apologize for any confusion this might have caused. We are aware that this PR does not resolve the issue and have an alternate approach that will be reviewed early next week. If it gets a sign off on the different approach, then I will start a patch update to NGO v1.10.1 that will include the alternate fix.

If you are having this issue and using fixed strings, then you could update your manifest with this: "com.unity.netcode.gameobjects": "https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git?path=com.unity.netcode.gameobjects#fix/fixedstring-byte-writing-and-comparing",

And report back here if that resolves your issue.

I have tested this very extensively for my game, and we have had no issues with fixedstrings. We use a lot of fixedstrings in INetworkSerializable structs to contain web IDs that don't change after the player connects. We also use some fixedstrings as NetworkVariables to store JSON data of things like dictionaries of game settings. So far, it's behaving just like 1.8.1 had been, no bugs or errors being logged server side or client side. This is with a ping upwards of 200 ms.