Skip to content

Awaiting Addressable.LoadAssetAsync and Yield hangs in Editor #580

Closed as not planned
@Mangatome

Description

@Mangatome

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions