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

Awaiting Addressable.LoadAssetAsync and Yield hangs in Editor #580

Open
Mangatome opened this issue May 3, 2024 · 0 comments
Open

Awaiting Addressable.LoadAssetAsync and Yield hangs in Editor #580

Mangatome opened this issue May 3, 2024 · 0 comments

Comments

@Mangatome
Copy link

Mangatome commented May 3, 2024

Hello. I am experiencing an odd behavior in the editor (2020.3.48f1) with the latest 2.5.4, where the statement await Addressables.LoadAssetAsync<TextAsset>(key) hangs when ran in edit mode.

By "hangs", I mean that the statement does not return unless I manually trigger an editor update by refreshing the scene or interacting with editor UI (e.g. resizing the game view).

In trying to reproduce this issue, I have isolated an interesting issue that sounds possibly related to my problem. Try to run the following code in the editor:

[InitializeOnLoadMethod]
private static void OnEditorStarts()
{
	UniTask.Create(async () =>
	{
		await Addressables.InitializeAsync();
		Debug.LogError("!init");

		for (int i = 0; i < 10; i++)
		{
			var a = Addressables.LoadAssetAsync<TextAsset>("some_addressable_asset.txt");
			try
			{
				await a;
			}
			finally
			{
				Addressables.Release(a);
			}

			Debug.LogWarning(i);

			await UniTask.Yield();
		}
		Debug.LogError("!asset");
	})
		.Forget();
}

You should observe two log lines: "!init" and "1". The code is hanging on await UniTask.Yield().
Now, if you interact with Unity, the task continues and you will see "2", "3", etc as long as you keep interacting with Unity. If you don't move, nothing happens.

Commenting await UniTask.Yield(), on the other hand, makes this work correctly.

It gets even weirder. If you add another await UniTask.Yield() before the for loop, this one continues correctly. Same if you comment await a instead of await UniTask.Yield(). So the issue seems to be not specifically in await UniTask.Yield() or await a in the combination of the two. How can it be?

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

1 participant