BeardedManStudios / ForgeNetworkingRemastered

See various forks, also please join the Forge Community fork of Forge Alloy! -> https://github.com/ForgeAlloyCommunity/ForgeAlloy
https://twitter.com/FarrisFaulds
Apache License 2.0
1.49k stars 306 forks source link

localServerLocated callback not executing all code #242

Closed Gentatsu closed 5 years ago

Gentatsu commented 5 years ago

Version Number and Operating System(s): Unity 2018.3.7f1 & Forge 25.01

Expected behavior: Code in callback to work (Instantiating game objects or other 3D object manipulation)

Actual behavior: Code does not get executed beyond trying to use any Gameobject references.

Steps to reproduce:

Add callback to localServerLocated Any code manipulating endpoint data works fine. Try to Instantiate a gameobject or change any properties (or call GetComponent), and it will stop executing without an error.

[Optional] Discord Username:

NFMynster commented 5 years ago

What's your Discord username? If you're on not there, I would recommend you to make an account. All support and such happens there and i would like to ask you some questions about this. Else, we'll take it here

NFMynster commented 5 years ago

Oh wait, you need to run it inside the main thread manager, as it's an Forge event. https://github.com/BeardedManStudios/ForgeNetworkingRemastered/wiki/Running-Unity-Specific-Code-on-the-Main-Thread

Gentatsu commented 5 years ago

I thought it might've been a main thread issue. Would it be possible to add a warning/error when code that requires main thread execution tries to execute on a separate thread?

I'll give it a try and let you know if it works. I'll also try make a Discord account!

Gentatsu commented 5 years ago

I circumvented the issue initially by setting a boolean, and in the Update function, I set a timeout of 0.5 seconds for the UDP announcements, and perform my function then (showing a list of hosts).

I would rather just add each host on the callback, though!

NFMynster commented 5 years ago

The Unity editor should have given you an error. Though, why not just use the MainThreadManager.Run() inside your event method? That should do it

Gentatsu commented 5 years ago

No errors! I didn't know about the Main thread manager =P!

I did try it, and it's still not working!

I'm calling it using a lambda function: MainThreadManager.Run(() => AddRow(endpoint));, and it's giving me the same issue. Again, no errors!

NFMynster commented 5 years ago

Can you show me the fullcode?

Gentatsu commented 5 years ago

https://pastebin.com/9NePFfxq

Refresh is called on a button OnClick. I've commented some of it out since I was doing a refresh check for a host every second, but also had the manual button.

NFMynster commented 5 years ago

You are still running Unity code inside the Forge event. Just wrap the whole entire "LocalServerLocated" in it, so it look something like this: https://pastebin.com/7kL5g47M

Gentatsu commented 5 years ago

Debug.Log was in the example in the documentation, and runs fine.

When I wrap it up like in yours, none of it gets called.

NFMynster commented 5 years ago

Join the Discord and let's have a chat

Gentatsu commented 5 years ago

Issue was asset store version. This works in the latest of master branch release.