FishNet icon indicating copy to clipboard operation
FishNet copied to clipboard

Network transform not able to receive and sync data in webgl (chrome)

Open AviMersiv opened this issue 1 year ago • 2 comments

Important

If General, Description, and Replication are not completed the issue will be closed immediately.

General Unity version: 2022.3.30f1 Fish-Networking version: 3.11.16R Discord link: https://discord.com/channels/424284635074134018/1034477094731784302/1211676546868318249 ** Above, post a link from our Discord where you troubleshot the issue (on Discord click the three dots next to the message, then Copy Message Link). Issue may be closed out if this is not included.

Description Hi My project is mainy for webgl (not editor) mainly working on chrome/edge/safari I created a simple scene with 2 players both having network transform I run the server on local host , and 1st client via the unity editor 2nd client via web local host (chrome)

the bug im facing : when the player in chrome aka 2nd client is moving the 1st client aka editor is being able to get the data from him and sync his movements (via the network transform component) but when i try the other way around moving from editor and receiveng in webgl I get instant exception in webgl MissingMethodException: Default constructor not found for type FishNet.Component.Transforming.NetworkTransform+GoalData for some reason the goaldata under the network transform is not being transfared correctly

Replication Steps to reproduce the behavior:

  1. make a simple prefab with network transform and network object components
  2. make simple scene with netwrok manager and add the prefab under the player spawner
  3. build dedicated server to run on local host
  4. run editor as client
  5. build webgl and run as 2nd client
  6. move in editor and bug should be reproduced data wont transfar and there will be network transform goal data exception in chrome

Expected behavior expected will be that movement from the editor will be able to sync to the webgl just as expected from the network transform component

Screenshots If applicable, add screenshots to help explain your problem.

image

AviMersiv avatar Feb 26 '24 15:02 AviMersiv

I was able to solve it with a workaround : I added under the NetworkTransform awake() a call for the goaldata builder like this:

private void Awake() { _interval = Math.Max(_interval, (byte)1); GoalData goalData = new GoalData(); }

the issue was initated because in webgl: because the constructor of goal data was not being called directly but from the createInstance.(follow belot the whole flow) its being stripped from the compiling process and therefore we get the exception of default constructor not found

flow its being called via the function :

networktransform :: DataReceived() -> GoalData nextGd = ResettableObjectCaches<GoalData>.Retrieve(); -> objectcaching:: retrive -> public static T Retrieve() { if (_stack.Count == 0) { return Activator.CreateInstance<T>(); } else { return _stack.Pop(); } }

            return Activator.CreateInstance<T>();

this line is causing the exception and i explained above why it being stripped because the constructor is not being called directly adding a empty call for the constructor fixed the issue , and no exceptions anymore from the network transform in webgl hope it helps :)

AviMersiv avatar Feb 26 '24 19:02 AviMersiv

This is caused by Unity stripping code.

I'll get this resolved in the next few days. In the mean time you can fix it yourself by adding this...

[Preserve]

Above the following like so:

            [Preserve]
            public RateData() { }
            [Preserve]
            public GoalData() { }

Resolved in 4.2

FirstGearGames avatar Mar 20 '24 15:03 FirstGearGames