Skip to content

Conversation

@Nietod
Copy link
Contributor

@Nietod Nietod commented Feb 7, 2026

This fixes #3654

Problem
SyncVar writes in generic base classes are emitted as FieldReference even within the same assembly.
The Weaver currently treats all FieldReference writes as cross-assembly access and errors.

I tested around and so basically the moment you got something like mySyncVar = <someValue> in your generic class, no matter if its in a method or the constructor, you will recieve the following error:

error '[SyncVar] Base1.syncvar' in 'Assembly-CSharp.dll' is modified by 'System.Void Base1::.ctor()' in 'Assembly-CSharp.dll'. Modifying a [SyncVar] from another assembly is not supported. Please add a: 'public void Setsyncvar(value) { this.syncvar = value; }' method in 'Base1' and call this function from 'System.Void Base1::.ctor()' instead.

using Mirror;

public class Base<T> : NetworkBehaviour
{
    [SyncVar]
    public bool syncvar = true; // Triggers the error

    public Base()
    {
        syncvar = false; // Triggers the error
    }
}

This error has its roots in the SyncVarAttributeAccessReplacer.cs and still occurs in the latest version of Mirror.

Fix
Resolve FieldReference and allow SyncVar writes when the resolved FieldDefinition belongs to the same module.

Result
SyncVars in generic base classes can now be written without triggering false cross-assembly errors.
Unit Tests passed normally and in a basic test scenario the syncVars worked as expected by syncing the correct values.

@MrGadget1024 MrGadget1024 added enhancement New feature or request Weaver Bug caused by Weaver Needs Unit Test Please add a unit test before we merge it labels Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Needs Unit Test Please add a unit test before we merge it Weaver Bug caused by Weaver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting a SyncVar in a Generic results in an error

2 participants