Skip to content

Unity cannot compile when extending NetworkBehaviour in Generics #2633

Description

@JohnnyRacket

Description

After refactoring code to have generic base types, Unity refused to compile until all generics with types extending NetworkBehaviour were swapped to MonoBehaviour

Reproduce Steps

  1. Create a generic that extends NetworkBehaviour, such as: public abstract class BaseActionController<ActionType,CharacterType> : NetworkBehaviour where ActionType : BaseAction<CharacterType> where CharacterType : NetworkBehaviour

  2. Try to compile and run project.

Actual Outcome

Unity.Netcode.Editor.CodeGen.NetworkBehaviourILPP: (0,0): error - System.NullReferenceException: Object reference not set to an instance of an object

Expected Outcome

Code compiles.

Environment

  • OS: Windows 11
  • Unity Version: 2023.1.0b20
  • Netcode Version: 1.5.1
  • Netcode Commit: 7a969f8

Additional Context

For now I have managed to replace the code with extending MonoBehaviour and it compiles, but it does not seem like an ideal limitation as I may have to assert types down the road.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions