-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullReferenceException: Object reference not set to an instance of an object Unity.Netcode.FixedStringSerializer`1[T].WriteDelta #2920
Comments
I'm also encountering this issue. It specifically occurs when Unity tries to serialize a My code works fine on NGO 1.8.1, but not on 1.9.1 |
I have also encountered this issue, on one of my network variables |
I have the same error when updating to NGO 1.9.1. The error occur the second time I update my variable EnvironmentWindows 11 |
Same issue in Netcode for GO 1.9.1. Couldn't find the root cause, could be transport class maybe?
|
I wanna tip in on this, as I get the same - it happens when upgrading to NGO 1.9.1. In 1.8.1 this works fine. For me it happens when I set a FixedString64Bytes. As said, the exact same code works fine in 1.8.1. As other mentions, it's like it's when it's set after Spawned, so like second time, and then it just keep spamming with this error and the NetworkVariable is never set. Which kind of make sense as the error indicate something is wrong in the "write/sending" part.
My manifest.json
|
Now I reverted back to NGO 1.8.1 as the ONLY change and now it works again. So something is clearly wrong :) |
Hello ! Best regards |
@Ufabsther This script is on my Player prefab, which are obviously instantiated when a player joins. As mentioned, the exact same code works fine in 1.8.1. Errors start happening when I press HOME or END as you can see in Update() its how I currently change character.
|
hi, i just upgraded to 1.9.1, found the solution.
to Edit: Edit: |
This is the Solution I found 12 hours ago was creating a new struct, that fixed it and made it worked for me. Or you just use the Solution of @matus-d-ui42 But here is an example, where Im using it for Player ID: private NetworkVariable<NFixedString32ID> PlayerID = new NetworkVariable<NFixedString32ID>(new NFixedString32ID { _id = "WrongID" }, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
public struct NFixedString32ID : INetworkSerializable //NFixedString32ID stands for New Fixed String 32 bytes used for Identification
{
public FixedString32Bytes _id;
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
serializer.SerializeValue(ref _id);
}
public string Value()
{
return _id.ToString(); //The same as ToString()
}
public void SetValue(string newValue)
{
_id = newValue;
}
public override string ToString()
{
return _id.ToString();
}
} |
Disclaimer: I don't know what I'm doing, but I got things working for myself. I added on to the fix by @matus-d-ui42 to fix two other errors I got afterwards that unfortunately I didn't record but were along the lines of not finding a Serializer and not using TryBeginRead() before using ReadByte(). I was able to fix it by adding the following to
|
Same problem here :( |
Just upgraded as well from 1.9.1 to 1.8.1 and it seems working fine for me. |
having the same issue, @matus-d-ui42 solution seems to fix it for me at the moment |
Hi everyone! A fix for this issue is in progress, but I just wanted to mention a couple of workarounds that can be used in the short term until the fix gets released: First option: put this attribute on any class or method anywhere in your codebase: [GenerateSerializationForType(typeof(byte))] Second option: put this class anywhere in your codebase: class Unused : NetworkBehaviour
{
NetworkVariable<byte> workaround;
} It doesn't need to be referenced anywhere, it just has to exist. Either one of those will trigger the codegen to correctly generate serialization code for |
Thanks @ShadauxCat ! However, it's not only an issue with bytes - actually it seem to be more a problem for us using FixedString. |
According to @ShadauxCat , FixedString are serialized as byte therefore the underneath issue was byte serialization |
Ok fair - make sense :) |
Thanks for this fix :) was simple enough to add, and haven't seen any issues since. |
Sadly none of these works for me - but it change my error to this and it's not spamming anymore, just one per action that causes this (changing a NetworkVariable with a FixedString. Just upgraded to Unity 2022.3.38, which auto updates to NGO 1.9.1 too. Sadly have to revert to NGO 1.8.1 again.
|
Yeah @Laumania that's the error I had too. Did you try the fix I mentioned above to add "reader.TryBeginRead(i);" in the right spot? You can find the exact spot by following the error you get. |
No, but thanks for sharing, however, I don't want to make changes to the NGO source like that. Hoping for an update soon that fixes it :S |
We are aware the v1.10.0 fix didn't really fix the issue. And report back here if that resolves your issue. |
I had the same issue, this solution fixed it on my side! Thanks! |
@W3ktor |
I have tested this in my game now too and it seems to fix the issue! Can't wait for the real update :) |
Description
It's hard to be precise with this issue as I'm unsure exactly what's causing it.
But in one of my scenes, I get the following error:
It continuously spams the log while the game is playing.
I've attempted to track down which object it is related to, and I've managed to delete an object, and even a script, which then stops the issue, but then it seems to come back again after a restart related to a different object. I couldn't track down any code that could've caused this - and with the stacktrace being entirely inside of Netcode, it's hard to figure it out.
The weird part is, as far as I remember, I had netcode 1.9.1 working in this exact scene with no errors for a while. I keep a full git history, so I went back to a point where it was working previously, and it is no longer working.
I've deleted the Library, obj and other folders and still no luck.
There are cases where I've been trying to narrow down the object thats creating this bug - and I play the game with that object deleted, and still get the bug. But then I play the game again, and then the bug isn't there - and I haven't changed anything since the last play.
If I leave said object deleted, restart Unity, then the first play will have this error, subsequent ones will not...
This scene works completely fine in NGO 1.7.1 & 1.8.1
Environment
Windows 11
NGO 1.9.1
Unity 2023.2.9f1
The text was updated successfully, but these errors were encountered: