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

No writer found error #2579

Closed
illusiveray opened this issue Feb 16, 2021 · 38 comments
Closed

No writer found error #2579

illusiveray opened this issue Feb 16, 2021 · 38 comments
Assignees
Labels
bug Something isn't working

Comments

@illusiveray
Copy link

illusiveray commented Feb 16, 2021

Describe the bug
I get the "No writer found for PlayerStats. Use a type supported by Mirror or define a custom writer" error when calling a ClientRpc method.

Reimport or edit script to trigger the compile process can solve this issue, but it will appear again after restart Unity.

The method is:
[ClientRpc]
void RpcSyncPlayerStats(PlayerStats[] _playerStatsArray)

PlayerStats is a class, and each field has a supported data type.

To Reproduce
Every time run the game after restart Unity, but I can't reproduce it in an empty project.

Desktop (please complete the following information):

  • OS: Windows
  • Build target: Android, standalone
  • Unity version: 2019.4.19
  • Mirror branch: v30.5.0
@Chillu1
Copy link
Contributor

Chillu1 commented Feb 22, 2021

Had the same problem. But mine is a bit weirder, I'm using a readonly struct with strings and ints. And whenever I open the project again, it prints out the error, but everything happens like expected (?).
I can fix it by changing any code related to the struct. But it comes back when I reopen the project.
Making a custom writer also fixes it, but forever this time

Desktop. Linux (arch LTS), Standalone, 2020.2.5f1, v30.5.1

@john-ofg
Copy link

john-ofg commented Feb 23, 2021

I have also encountered this issue since upgrading Unity and Mirror in my project recently.
OS: Windows
Build targets: Windows 64bit player, Linux 64bit headless
Unity version: Unity 2020.2.3f1 and 2020.2.4.f1
Mirror branch: v30.2.1

On my project it only seems to happen with structs that contain another struct.

@JesusLuvsYooh
Copy link
Contributor

Same, few posts here about it.
Mine seems to be on about sync list scores, game carries on fine despite the random red error.
https://discord.com/channels/343440455738064897/467961191864598528/813706860229820426

@JesusLuvsYooh
Copy link
Contributor

JesusLuvsYooh commented Feb 24, 2021

Screenshot 2021-02-24 at 17 33 26
Related

[Serializable]
public struct SyncSceneScores
{
    public string name;
    public int points;
    public uint netid;
}

@MrGadget1024
Copy link
Collaborator

Desktop. Linux (arch LTS), Standalone, 2020.2.5f1, v30.5.1

Do you have this package installed?

image

@Chillu1
Copy link
Contributor

Chillu1 commented Feb 24, 2021

Desktop. Linux (arch LTS), Standalone, 2020.2.5f1, v30.5.1

Do you have this package installed?

image

Yes, but V2.0.5. Updated to V2.0.7 and checked again (for the error).
Issue still persist

@leonard4
Copy link

leonard4 commented Mar 5, 2021

Seeing the same issue on 2019.4.21f1 with VS2019 and Mirror v32.1.3. Saving any script fixes the issue. Been chasing this one for months, but can't seem to nail it down.

image

@iceb111
Copy link

iceb111 commented Mar 7, 2021

Never got this issue on 2020.1.17, but started getting it immediately after upgrading to 2020.2.6

@kamyker
Copy link

kamyker commented Mar 7, 2021

For me "Weaver: stop because compile errors on target" was the issue. In Unity 2020.2 warnings suppressed by roslyn analyzers are somehow treated as errors. Possibly "Suppress common warnings" option added in all 2018+ editors since this post https://forum.unity.com/threads/suggesting-solutions-for-serializefield-warning.962112/page-2#post-6762493 triggers it.

I recommend adding ERROR log to weaver to see what stops it.

https://github.com/vis2k/Mirror/blob/020f79a8d2b7864ef48b71f85d6cf0ffdcad6f1c/Assets/Mirror/Editor/Weaver/CompilationFinishedHook.cs#L85-L88
Change to:

static bool CompilerMessagesContainError(CompilerMessage[] messages)
{
    foreach (var msg in messages)
    {
        if (msg.type == CompilerMessageType.Error)
        {
            Debug.LogError(msg.message);
            return true;
        }
    }
    return false;
}

Analyzers fix:

static bool CompilerMessagesContainError(CompilerMessage[] messages)
{
    foreach ( var msg in messages )
    {
        if (msg.type == CompilerMessageType.Error 
             && !msg.message.Contains("was programmatically suppressed by a DiagnosticSuppressor" ))
        {
            Debug.LogError(msg.message);
            return true;
        }
    }
    return false;
}

@JesusLuvsYooh
Copy link
Contributor

@JamesMcGhee
Copy link

JamesMcGhee commented Mar 11, 2021

Seeing the same issue using the latest version of Mirror from the Unity Asset Store

As with others if we right click on teh folder and select reimport to force it to recompile the issue goes away though returns every time we open the project and we suspect is also present in builds from Unity Cloud Build

As a result this has our project stoped ... so we are going to try and revert to 30.5.1 to see if that helps ... belive Lange from Discord comunity said that helped them

@JamesMcGhee
Copy link

From what we can tell this happens on any non-primative thing that need serialize
So when we have a SyncList or when we have CMD that use such.

We had ran quite a while with these structures on an older version (dont recall specificly what version) ... point is we know the model we are working with did work and no longer does. It does work after you reimport ... until you restart the project. This however is not a sufficent workaround to the issue since we use cloud build and we cant very well reimport on the build server before we build.

At the moment this is a show stoper e.g. has stoped the project outright.

@miwarnec
Copy link
Collaborator

hey guys. on my phone right now but please share step by step guide on how I can reproduce it. will check it out today.

@miwarnec miwarnec self-assigned this Mar 12, 2021
@miwarnec miwarnec added the bug Something isn't working label Mar 12, 2021
@miwarnec
Copy link
Collaborator

back home.
read through everything, looks like there's no instruction on how to reproduce it.
please add instructions, then I can fix it

@JesusLuvsYooh
Copy link
Contributor

For me it seems to appear when i use sync lists:
https://hatebin.com/cdjkrzfetq

@JamesMcGhee
Copy link

For us the common issue seems to be non-primative objects for example

we have a structure (example only)

[Serializable]
public struct Payload
{
public string somedata;
...
}

That doesn't work, we get the reader errors rather its used in a SyncList, SyncVar or CMD/RPC we always get issues

We have other SyncVar and Lists that are primative and get no errors/warnings about them

When we reimport the Mirror folder the issue goes away

On 2019 running an older version of Mirror (17.3.0) the same structures and code worked with no issue at all

I have not tried to reproduce in a smaller project but if you need I can give it a go ... at the moment I am focused on trying to work around the issue as this does have us at a hard stop.

@miwarnec
Copy link
Collaborator

miwarnec commented Mar 12, 2021

are you guys using Unity 2020?
I actually just got the same error with 2020.3 LTS.
I opened it, rebuild scripts once and then simply ran tests.
editor in release mode.

also just noticed that unity adds changelog.txt files to our weaver tests in the ~ folder. might be related.

2021-03-12_18-14-36@2x

@illusiveray
Copy link
Author

I have tried, but I can't reproduce this issue in an empty project. It's strange.

@DanielTizon
Copy link

I'm getting the same error with Unity 2020.3 LTS and last Mirror version.

I'm using ummorpg 2d remastered and I'm getting this error:

No writer found for Skill. Use a type supported by Mirror or define a custom writer
UnityEngine.Debug:LogError (object)
Mirror.NetworkWriter:Write<Skill> (Skill) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkWriter.cs:128)
Mirror.SyncList`1<Skill>:OnSerializeAll (Mirror.NetworkWriter) (at Assets/uMMORPG/Plugins/Mirror/Runtime/SyncList.cs:116)
Mirror.NetworkBehaviour:SerializeObjectsAll (Mirror.NetworkWriter) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkBehaviour.cs:632)
Mirror.NetworkBehaviour:OnSerialize (Mirror.NetworkWriter,bool) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkBehaviour.cs:559)
Mirror.NetworkIdentity:OnSerializeSafely (Mirror.NetworkBehaviour,Mirror.NetworkWriter,bool) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkIdentity.cs:805)
Mirror.NetworkIdentity:OnSerializeAllSafely (bool,Mirror.NetworkWriter,int&,Mirror.NetworkWriter,int&) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkIdentity.cs:859)
Mirror.NetworkServer:CreateSpawnMessagePayload (bool,Mirror.NetworkIdentity,Mirror.PooledNetworkWriter,Mirror.PooledNetworkWriter) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkServer.cs:787)
Mirror.NetworkServer:SendSpawnMessage (Mirror.NetworkIdentity,Mirror.NetworkConnection) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkServer.cs:811)
Mirror.NetworkServer:ShowForConnection (Mirror.NetworkIdentity,Mirror.NetworkConnection) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkServer.cs:719)
Mirror.NetworkConnection:AddToObserving (Mirror.NetworkIdentity) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkConnection.cs:116)
Mirror.NetworkIdentity:AddObserver (Mirror.NetworkConnection) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkIdentity.cs:1014)
Mirror.NetworkServer:SpawnObserversForConnection (Mirror.NetworkConnection) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkServer.cs:1027)
Mirror.NetworkServer:SetClientReady (Mirror.NetworkConnection) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkServer.cs:677)
Mirror.NetworkServer:AddPlayerForConnection (Mirror.NetworkConnection,UnityEngine.GameObject) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkServer.cs:572)
NetworkManagerMMO:OnServerCharacterSelect (Mirror.NetworkConnection,CharacterSelectMsg) (at Assets/uMMORPG/Scripts/NetworkManagerMMO.cs:668)
Mirror.MessagePacking/<>c__DisplayClass5_0`2<CharacterSelectMsg, Mirror.NetworkConnection>:<WrapHandler>b__0 (Mirror.NetworkConnection,Mirror.NetworkReader,int) (at Assets/uMMORPG/Plugins/Mirror/Runtime/MessagePacking.cs:116)
Mirror.NetworkConnection:UnpackAndInvoke (Mirror.NetworkReader,int) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkConnection.cs:147)
Mirror.NetworkConnection:TransportReceive (System.ArraySegment`1<byte>,int) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkConnection.cs:182)
Mirror.LocalConnectionToServer:Send (System.ArraySegment`1<byte>,int) (at Assets/uMMORPG/Plugins/Mirror/Runtime/LocalConnections.cs:75)
Mirror.NetworkConnection:Send<CharacterSelectMsg> (CharacterSelectMsg,int) (at Assets/uMMORPG/Plugins/Mirror/Runtime/NetworkConnection.cs:77)
UICharacterSelection:<Update>b__11_0 () (at Assets/uMMORPG/Scripts/_UI/UICharacterSelection.cs:52)
UnityEngine.EventSystems.EventSystem:Update () (at /home/tornar/Unity/Hub/Editor/2020.3.0f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:385)

@JamesMcGhee
Copy link

For us we had the issue on Unity 2020.2 and now on Unity 2020.3

In our case when we first open the project the issue is present, then we can right click on the Mirror folder and reimport and the issue is resolved. The problem as noted in our case is that our cloud builds cant do that second import on the Mirror folder so that little work around is okay for client only cases does nothing for conditions on the server that present this issue.

Its interesting that causing a recompile sorts the problem and that the problem seems to be built around structs .... that is SyncList and similar where its primatives that are being usesd are never noted its always some serializable struct that is called out as not having a writer.

@miwarnec
Copy link
Collaborator

from discord:
" Loden | Heathen Engineering
:
We managed to make it go away

Note what we did ... think this may be some pain in the arse from Collab

so

  1. we upgraded to 2020.3
  2. we moved to the latest on Git only a few hrs old so much newer than what we have from Unity
  3. we moved to KCP
  4. we had multiple issues with collab bing a pain about the 2019 to 2020 upgrade

what we think was the issue
We think Collab was forcing the library to pull down an old bad build of the Mirror project ... so we removed Mirror ... we checked in with Mirror gone ... we brought Mirror back from GIT and checked in and while doing that pain in the arse changed to KCP from Telepathy ... result ... issue is gone ... why FIIK (f&*^ if I know) ... dont really care after a week of issues the issue is gone ... its clearly some issue between weaver and Unity compiler but its gone now so we are happy and just want to move on"

@miwarnec
Copy link
Collaborator

tried 2020.3 again today.
tests fail on first import with writer not found error.

@miwarnec
Copy link
Collaborator

quick update: I am working on a fix. the bug was introduced in the weaver several months ago.
need to roll back several months of changes so this will take a bit longer.

miwarnec added a commit that referenced this issue Mar 22, 2021
before 6cfdd64 "Simplify type lookup in weaver (#2258)"
=> adjusted for requireAuthority double negative already
=> adjusted for weaver.Emit already
@miwarnec
Copy link
Collaborator

miwarnec commented Mar 25, 2021

for reference, here is the commit that started it:
#2317

from discord: both 2019 and 2020 add the generated writers.
but in 2020 we have GeneratedNetworkCode twice;
2021-03-25_16-39-36@2x

@miwarnec
Copy link
Collaborator

2020 with GeneratedNEtworkCode random suffix:
2021-03-25_16-48-24@2x

now it's only one. it also contains the generated code for BadMessage.
but for whatever reason, writer.Write() doesnt call the generated code.

@miwarnec
Copy link
Collaborator

2021-03-25_16-49-37@2x

@miwarnec
Copy link
Collaborator

InitReadWriters is supposed to be called on load:
image

but doesn't look like it is called

@miwarnec
Copy link
Collaborator

it's called in 2019, but I never saw it in 2020:
image

@miwarnec
Copy link
Collaborator

2019 has [InitializeOnLoad] attr which is why tests work:
image

@miwarnec
Copy link
Collaborator

gotta head out soon. to summarize, there are two issues:

  1. in 2020, Weaver.IsEditorAssembly returns false for Mirror.Tests.dll because Unity most likely strips unused assemblies there. [RuntimeInitializeOnLoad] is added but that's not called for tests.

  2. supposedly [RuntimeInitializeOnLoad] isn't 100% reliable either since some people reported the bug for 2019 rarely too

@miwarnec miwarnec reopened this Mar 26, 2021
@miwarnec
Copy link
Collaborator

pushed a fix to master to guarantee that [InitializeOnLoad] is always called in Editor.
this should fix all 'no writer found' errors when in Editor.

not sure if anyone encountered 'no writer found' at runtime though.
please test and let me know if this fixes your issues guys.

(simply download mirror master from github)

@miwarnec
Copy link
Collaborator

reading through it again, it sounds like you all encountered the error in the editor.
that's what I fixed.
please reopen if you still see the error.

@miwarnec miwarnec reopened this Mar 26, 2021
@miwarnec
Copy link
Collaborator

still happens in 2019 for match example.

2021-03-26_19-43-42@2x

@miwarnec
Copy link
Collaborator

for the above repro:

  • it DOES NOT happen when deleting library folder and trying for the first time
  • it DOES happen when the library folder already exists, we open project in unity, then try

@miwarnec
Copy link
Collaborator

from discord:
when restarting unity, it tries to weave the mirror.tests.dll again.
it's obvious when adding a random suffix to GeneratedNetworkCode:
image

the second generated ones doesn't have mrgadget's Matchplayerdata as reader for some reason.

@MrGadget1024
Copy link
Collaborator

To everyone following this ticket, please try master branch as soon as possible to confirm we have this fixed, and come to Discord and tell us if not. Thanks!

@leonard4
Copy link

Just loaded up v35.1.0 and so far so good, Writer error is gone! Not having to edit/save/reload any script to force a reload. Everything appears to be working, thanks guys.

@ratBytes
Copy link

ratBytes commented Apr 8, 2021

Thank you guys. Can confirm. No more Writer errors <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests