Skip to content

Custom Network Variables do not trigger Code Generation for Network Serialization #2686

@Reag

Description

@Reag

Description

In order to deal with problem specific to my team's use case (shared simulations), I started created a version of the NetworkList that only sends the final delta, rather than every delta processed between update loops (The internal events for triggering read and write delta are handled via a list with only unique elements, keyed to the network operation).

When I went to test this, I got the following error:

ArgumentException: Type Unity.Netcode.NetworkBehaviourReference is not supported by NetworkVariable`1. If this is a type you can change, then either implement INetworkSerializable or mark it as serializable by memcpy by adding INetworkSerializeByMemcpy to its interface list. If not, assign serialization code to UserNetworkVariableSerialization.WriteValue, UserNetworkVariableSerialization.ReadValue, and UserNetworkVariableSerialization.DuplicateValue, or if it's serializable by memcpy (contains no pointers), wrap it in ForceNetworkSerializeByMemcpy`1.

However, adding a NetworkVariable to my code caused it to run fine. This leads me to believe that in some cases the necessary code generation for serialization isn't being triggered by user created classes that extend NetworkVariableBase.

Reproduce Steps

  1. Create a custom NetworkVariable class that extends NetworkVariableBase (Mine is provided below)
  2. Create a NetworkBehaviour that uses this variable. Set its type to some INetworkSerializable struct.
  3. Run as server and connect a client via parallel sync.

Actual Outcome

The error above occurs and the var fails to sync. Adding a NetworkVariable in the same code will then make it pass.

Expected Outcome

It just works

Screenshots

image

Removing the comments makes it so clients can sync.

Environment

  • Unity Version: 2022.3.6f1
  • Netcode Version: 1.5.2

Additional Context

I'm assuming its an issue with the code generation, as that is what seems logical to me. I could also be completely wrong, as I have only just started diving into the internals of NFGO for this task. The Dictionary/List I'm using for testing can be found here (https://hastebin.com/share/nutasejize.csharp). This particular class is not fully complete yet (No code review or heavy testing) and may contain bugs.

[Edit1]: Updated example code to a newer version

Metadata

Metadata

Assignees

Labels

priority:highThis issue has high priority and we are focusing to resolve itstat:importedStatus - Issue is tracked internally at Unitytype:bugBug Report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions