Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Although scheduling on MainThread still getting error that API accessed from other thread. #261

Open
Zammy opened this issue Nov 21, 2017 · 1 comment

Comments

@Zammy
Copy link

Zammy commented Nov 21, 2017

I am getting this error

SetString can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEditor.EditorPrefs:SetString(String, String)

		Observable.ReturnUnit()
			.SubscribeOn(Scheduler.ThreadPool)
			.Select(_ => {Debug.Log("Print!"); return Unit.Default;})
			.SubscribeOn(Scheduler.MainThread)
			.Subscribe(_ => EditorPrefs.SetString("key", "data"));

What am I doing wrong?

This is executed inside EditorWindow.

@Lailore
Copy link

Lailore commented Nov 22, 2017

You need use ObserveOnMainThread. Not SubscribeOn.
https://stackoverflow.com/questions/20451939/observeon-and-subscribeon-where-the-work-is-being-done

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

No branches or pull requests

2 participants