Unity-Technologies / multiplayer-community-contributions

Community contributions to Unity Multiplayer Networking products and services.
MIT License
429 stars 161 forks source link

NullReferenceException when using SteamP2P Transport #122

Closed maxkerpen closed 2 years ago

maxkerpen commented 2 years ago

I am using the SteamP2P Transport and have a simple setup for a lobby in unity. When trying to join a hosted game as a client, after a few seconds a NullReferenceException gets thrown in the NetworkManager.cs, at line 1144: MessagingSystem.ProcessIncomingMessageQueue();

Then the NetworkManager.Singleton.OnClientDisconnectCallback is called, against what the NetworkManager.Singleton.OnClientConnectedCallback never gets called (so the client never connects properly).

Here are two threads, where people describe the similar problems:

  1. https://answers.unity.com/questions/1869491/messagingsystemprocessincomingmessagequeue-nullref.html?childToView=1870613
  2. forum.unity.com/threads/anyone-have-sample-mlapi-with-steam-matchmaking.1098304/

I am using:

juzdepeche commented 2 years ago

Same issue for me, here is my repo with my environment if it can help to find the problem.

Szaary commented 2 years ago

Same issue. Actualy i did not found any way to connect clients to hosted game using SteamP2P right now.

JamesMcGhee commented 2 years ago

New SteamNetworking Transport transport available in the community transports.

The new one Does Not ship Steamworks.NET with it so you would need to have Steamworks.NET installed such as from its author. They have Package Manager install instrucitons now as well.

Can you let me know if you have the same issue with it? Its very similar to the older SteamP2P but cleans up a few things with how the Steam API is used and is no longer dependent on SteamManager which could be an issue in some cases if you had your own integration with Steam set up or where using a newer version of Steamworks.NET

This new approch also means you can be using the latest Steamworks.NET so that will help eliminate the issue being an old Steamworks.NET bug or a bug with the old SteamP2P transport's custom take on Steamworks.NET

maxkerpen commented 2 years ago

Unfortunately I still have the same issue.

I tested the new SteamNetworking Transport both with the old SteamManager as well as the Steamworks V2 Foundation (free). Both resulted in the same error which I described in the original post.

nyan-left commented 2 years ago

Same issue here.

ElwoodHogan commented 2 years ago

Same issue. If anyone has a working project that uses SteamP2P Transport, itd be really helpful

styliann-eth commented 2 years ago

Exactly the same issue here - I'm almost relieved to see that so many of you guys are also experiencing this to be honest..

@JamesMcGhee this is what I was telling you about yesterday on the Heathen Engineering chat.

Note that I've tried to provide the SteamNetworkingTransport component with the CSteamID to connect to manually (in the method triggered by the Evt Game Created event of the LobbyManager) but it didn't change anything.

JamesMcGhee commented 2 years ago

Exactly the same issue here - I'm almost relieved to see that so many of you guys are also experiencing this to be honest..

@JamesMcGhee this is what I was telling you about yesterday on the Heathen Engineering chat.

Note that I've tried to provide the SteamNetworkingTransport component with the CSteamID to connect to manually (in the method triggered by the Evt Game Created event of the LobbyManager) but it didn't change anything.

My point was that the Steam P2P transport should be depricated and replaced by the

SteamNetworking transport listed here

https://github.com/Unity-Technologies/multiplayer-community-contributions/tree/main/Transports/com.community.netcode.transport.steamnetworking

This new transport is just a port of the older one but it updates the older one to work with modern version of Steamworks.NET

As far as a Null Ref I would have dig deeper into it honistly MLAPI / NetCode is its own beast we where simply looking to help port its old Steamworks based Steam P2P transport to use the modern flavor of Steamworks.NET

If you can proivide a stack trace as to where its breaking I might be able to take a guess as to what is going on ... assuming its Steamworks related and not somethign fundamental with MLAPI / NetCode

JamesMcGhee commented 2 years ago

Working with a developer on this issue from the point of view of Steamworks its self not the transport or MLAPI/NetCode directly.

Line 172 in the NetworkUpdateLoop.cs script is the point of failure for them ... it would seem that NetworkUpdateStage in the line

RunNetworkUpdateStage(NetworkUpdateStage.EarlyUpdate)

Is null ... so anyone have idea as to why that would be null, e.g. where and when should it be initalized and how does it get this far as a null without being caught? Is this something the transport should have initalized, or is this something the transport should have triggered the NetworkManager to initalize, etc.

We would need someone with more experience with MLAPI/NetCode for GameObjects to speak on these aspects

GZHhaha commented 2 years ago

Same issue...

LukeStampfli commented 2 years ago

For the Photon based transport #118 was necessary after the latest change. There was a change to how the ids need to be passed in the connected and message events.

JamesMcGhee commented 2 years ago

It will be some time before we can get back into the source code for this one

But, some tips if anyone else wants to take a swing at it

SteamNetworkingTransport.cs has a sub class in it

SteamNetworkingTransport.User

This is already tracked per user (hence the name) and holds the CSteamID and some ping info. You could likely just add a ulong unityId to that and update it when the user connects to do more or less what was done in change set #1368 from what I can see.

That said I haven't dove deep so not completly sure what is requried here just that I can see they are mapping IDs to each other and I do recall SteamNetworkingTransport already maintains a dictionary of user data

LukeStampfli commented 2 years ago

Took me a while to figure this out. Debugging steamnetworking is still a real pain 😄. The issue wasn't in the IDs but the channel code which was incorrect.

138 fixes the issue on my machine(s).

If anyone has time it would be great if you could test whether this version of the transport fully works as I only have a very simple sample project. Just add the following in the package manager via add by giturl:

https://github.com/Unity-Technologies/multiplayer-community-contributions.git?path=/Transports/com.community.netcode.transport.steamnetworking#bdb9850f7d4d59a3b2a0eb224949966c5a131a03
ElwoodHogan commented 2 years ago

I'm trying to implement the new fixes, but I'm still running into a few errors. Would it be possible to make a scene with a basic connection system implemented? I'm worried I've set something up wrong.

daniellochner commented 2 years ago

Hi @ElwoodHogan, did you ever manage to get it working? I'm having issues with Lobby not working properly with the Steam transport.