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

Custom Reader/Writer not active for NetworkMessages, but for SyncVars #916

Closed
Kerozard opened this issue Sep 4, 2021 · 0 comments · Fixed by #917
Closed

Custom Reader/Writer not active for NetworkMessages, but for SyncVars #916

Kerozard opened this issue Sep 4, 2021 · 0 comments · Fixed by #917

Comments

@Kerozard
Copy link

Kerozard commented Sep 4, 2021

Describe the bug
When adding a custom reader/writer for an abstract class, it works for synchronizing SyncVars, but when adding the abstract class as a field to a network message, an error message is produced after a recompile.

The error message: Error: (0,0): error Cannot generate read function for abstract class Foo. Use a supported type or provide a custom read function

Repro project

[NetworkMessage]
public struct FooMessage
{
  public Foo Foo;
}

public abstract class Foo {}
public class FooBar : Foo {}

public static class FooReaderWriter
{
  public static Foo ReadFoo(this NetworkReader reader)
  {
    var fooValue = reader.ReadInt32();
    return new FooBar();
  }

  public static void WriteFoo(this NetworkWriter writer, Foo foo)
  {
    writer.WriteInt32(0);
  }
}

To Reproduce
Steps to reproduce the behavior:

  1. Copy the attached code into a new cs file inside the project
  2. Compile
  3. See error

Expected behavior
Custom reader/writer should also work correctly for network messages.

Desktop (please complete the following information):

  • OS: Windows 10 Pro
  • Build target: PC, Mac & Linux Standalone
  • Unity version: 2020.3.16f1 (LTS)
  • Mirage version: 102.0.0
James-Frowen added a commit that referenced this issue Sep 4, 2021
James-Frowen added a commit that referenced this issue Sep 22, 2021
James-Frowen added a commit that referenced this issue Sep 23, 2021
* fix: fixing custom reader for abstract class

fixes: #916

* fixing fixing extension methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant