Skip to content
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

feat: Support for generic NetworkBehaviour types, and fix: issues with domain reload/scene reload being disabled #2720

Merged
merged 6 commits into from
Oct 3, 2023

Conversation

ShadauxCat
Copy link
Collaborator

Adds support for generic network behaviours, as well as for serializing generic types in RPCs (so long as the type is defined on the behaviour and not on the RPC itself; which is to say, this is supported:

public class Foo<T> : NetworkBehaviour
{
    [ServerRpc]
    public void MyServerRpc(T val) {}
}

But this is not:

public class Foo : NetworkBehaviour
{
    [ServerRpc]
    public void MyServerRpc<T>(T val) {}
}

As in the former case, when the class is instantiated, it knows what T is and there is only one version of the RPC per class, while the latter case would require much more significant plumbing for runtime type identification of RPC parameters in order to be able to instantiate the RPC correctly on the receiving side.)

In fixing this, the majority of the issues with domain reload were also fixed coincidentally, so I went ahead and fixed the couple of remaining issues as well.

Changelog

  • Fixed: Generic NetworkBehaviour types no longer result in compile errors or runtime errors
  • Fixed: Rpcs within Generic NetworkBehaviour types can now serialize parameters of the class's generic types (but may not have generic types of their own)
  • Fixed: Errors are no longer thrown when entering play mode with domain reload disabled
  • Fixed: NetworkSpawn is now correctly called each time when entering play mode with scene reload disabled

Testing and Documentation

  • Includes integration tests.
  • No documentation changes or additions were necessary.

fixes #1860
fixes #1879
fixes #2118
fixes #2608
fixes #2633
fixes #2647
fixes #2690
fixes #2693
fixes #2717
fixes #2719

@ShadauxCat ShadauxCat requested a review from a team as a code owner October 2, 2023 19:20
@RubenCoucke
Copy link

Any idea when this would be released?

@ShadauxCat
Copy link
Collaborator Author

@RubenCoucke I cannot give you an exact date, but this should be included in our next release, which should be coming out relatively soon.

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ShadauxCat ShadauxCat enabled auto-merge (squash) October 3, 2023 21:59
@ShadauxCat ShadauxCat merged commit d565d9d into develop Oct 3, 2023
1 check passed
@ShadauxCat ShadauxCat deleted the feat/generic_networkbehaviour_types branch October 3, 2023 22:36
NoelStephensUnity pushed a commit that referenced this pull request Oct 5, 2023
…h domain reload/scene reload being disabled (#2720)

Adds support for generic network behaviours, as well as for serializing generic types in RPCs (so long as the type is defined on the behaviour and not on the RPC itself; which is to say, this is supported:

```csharp
public class Foo<T> : NetworkBehaviour
{
    [ServerRpc]
    public void MyServerRpc(T val) {}
}
```

But this is not:

```csharp
public class Foo : NetworkBehaviour
{
    [ServerRpc]
    public void MyServerRpc<T>(T val) {}
}
```

As in the former case, when the class is instantiated, it knows what T is and there is only one version of the RPC per class, while the latter case would require much more significant plumbing for runtime type identification of RPC parameters in order to be able to instantiate the RPC correctly on the receiving side.)

In fixing this, the majority of the issues with domain reload were also fixed coincidentally, so I went ahead and fixed the couple of remaining issues as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment