Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
- Fixed issue where a client could throw an exception if abruptly disconnected from a network session with one or more spawned `NetworkObject`(s). (#2510)
- Fixed issue where invalid endpoint addresses were not being detected and returning false from NGO UnityTransport. (#2496)
- Fixed some errors that could occur if a connection is lost and the loss is detected when attempting to write to the socket. (#2495)
- Making a `NetworkVariable` with an `INetworkSerializable` type that doesn't meet the `new()` constraint will now create a compile-time error instead of an editor crash (#2528)

## Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ private void CreateNetworkVariableTypeInitializers(AssemblyDefinition assembly)
{
if (type.HasInterface(typeof(INetworkSerializable).FullName))
{
var constructors = type.Resolve().GetConstructors();
var hasEmptyConstructor = false;
foreach (var constructor in constructors)
{
if (constructor.Parameters.Count == 0)
{
hasEmptyConstructor = true;
}
}

if (!hasEmptyConstructor)
{
m_Diagnostics.AddError($"{type} cannot be used in a network variable - Managed {nameof(INetworkSerializable)} instances must meet the new() constraint.");
Comment thread
ShadauxCat marked this conversation as resolved.
Outdated
continue;
}
serializeMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeSerializer_ManagedINetworkSerializable_MethodRef);
}

Expand Down