Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.1k stars 430 forks source link

NetworkEarlyUpdate causing game to lag significantly ON ANDROID #2934

Open LightPat opened 1 month ago

LightPat commented 1 month ago

Description

NetworkEarlyUpdate taking WAY too long in profiler.

image

This happens every 3-5 frames in my game, ONLY ON ANDROID. To be clear, I'm not assigning values to a FixedString network variable frequently anywhere in my code. Yet, this network message is taking up so much frame time so frequently (25-35%). I think this might be related to #2920 , as my project was suffering from that bug too. On 1.8.1, I also have this problem.

Environment

Additional Context

This is the code for my NetworkString struct I'm using now, since FixedString doesn't work on its own. See issue #2920 image

LightPat commented 1 month ago

After further analysis, it appears that my lag is coming from too many client RPC calls. When I have 8 players or so, each time they play an attack (which happens pretty frequently it's a hack and slash game), it adds to the message queue. I can have all the players connected, and if I disable the attacking RPCs, my FPS is stable, and network early update no longer takes up 30% of frame time (0-3%). I debugged that the RPCs aren't getting sent every frame, so I'm confused as to why this is happening still

LightPat commented 1 month ago

Also, this problem occurs whether using the new [Rpc] attribute or the legacy [ServerRpc] and [ClientRpc] attributes