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

get_transform can only be called from the main thread. #10

Open
enviel opened this issue Dec 17, 2017 · 8 comments
Open

get_transform can only be called from the main thread. #10

enviel opened this issue Dec 17, 2017 · 8 comments

Comments

@enviel
Copy link

enviel commented Dec 17, 2017

what's the best practice to set something like transform inside On event

i'm not really experienced with multithreading, from the example all i can found is "lock" which i'm not sure what to put inside

		socket.On("pos", (data) =>
		{
			string str = data.ToString();
			Vector3 pos = JsonConvert.DeserializeObject<Vector3>(str);
			remotePlayer.transform.position = pos;
		});

i'm using fpanettieri's before using this, and i can do above script

@floatinghotpot
Copy link
Owner

Yes, the callback is running in a background thread, so not operate the UI in that.

Instead, put the data in a variable, the use the main thread to read the variable then operate the UI.

See the example:
https://github.com/floatinghotpot/socket.io-unity/blob/master/Demo/SocketIOScript.cs#L68

@enviel
Copy link
Author

enviel commented Dec 17, 2017

@floatinghotpot can you please update the lib to support the script that i'm doing?
just like how this lib work https://github.com/fpanettieri/unity-socket.io-DEPRECATED
crating a variable for every event seems unnecessary
if i have lots of events it's going to be messy

@floatinghotpot
Copy link
Owner

I think that is same, the callback is a background thread, you can write log, but you cannot access UI.

@enviel
Copy link
Author

enviel commented Dec 17, 2017

@floatinghotpot i'm not accessing UI, i'm accessing player gameobject transform
and i can do that in this lib https://github.com/fpanettieri/unity-socket.io-DEPRECATED
i can even access UI when using that lib

@floatinghotpot
Copy link
Owner

But your suggestion is good. If initialize a function in main thread to regularly check the queue then call your callback, it should be okay.

@enviel
Copy link
Author

enviel commented Dec 17, 2017

yeah and that should be a core element on the lib
can you add that to the lib?

@floatinghotpot
Copy link
Owner

I think that is not difficult, just add a wrapper. I will try.

@enviel
Copy link
Author

enviel commented Dec 17, 2017

@floatinghotpot thankyou so much sir :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants