Closed happimal closed 4 years ago
apologies for the slow response... which sample are you talking about?
I sincerely don't recall. I will ask around here if anyone has an idea of this issue. And if so I'll get back to you.
Actually, I'm confused by your SyncAddressables sample codes. Here is my code:
IEnumerator Start()
{
yield return Addressables.InitializeAsync();
yield return null;
yield return null;
yield return null;
yield return null;
Load<GameObject>("Assets/MainApp/Prefabs/GameLaunch.prefab");
Load<GameObject>("Assets/MainApp/Prefabs/_LBLibraryUnity_.prefab");
yield return null;
Load<GameObject>("Assets/Game/Prefabs/Spines/linepic003.prefab");
}
void Update()
{
Load<GameObject>("Assets/MainApp/Prefabs/GameLaunch.prefab");
Load<GameObject>("Assets/MainApp/Prefabs/_LBLibraryUnity_.prefab");
Load<GameObject>("Assets/Game/ColoringDraw/Prefabs/Spines/linepic003.prefab");
}
T Load<T>(string asset) where T:Object
{
var result = Addressables.LoadAssetAsync<T>(asset);
if (!result.IsDone)
{
// throw new Exception("Sync LoadAsset failed to load in a sync way! " + asset + " "+ result.OperationException);
}
if (result.Result == null)
{
var message = "Sync LoadAsset has null result " + asset;
if (result.OperationException != null)
message += " Exception: " + result.OperationException;
// throw new Exception(message);
}
Debug.Log("===>" + result.Result);
return result.Result;
}
It failed 3 times after initialized then worked properly, but why it failed 3 times?
you shouldn't comment out the "throw" calls if you want it to be forced to sync loading. I'm guessing those were failing, and your debug log is due to it doing async loads. After a few frames, the thing is loaded, so on subsequent calls, the op is done, and you're getting the completed operation back. Odds are the providers aren't quite set up right on the group.
Yes, I know. But if I don't comment on the "throw" calls, it will stop at these lines. My load API will be unuseful.
Besides, how could I know WHEN is the thing be loaded? And I could not use the complete CALLBACK as I'm writing a loading API for my team.
Also, I've done the InitializeAsync with "yield return".
one of they key purposes of this demo is to show that sync loading is really fragile and hard to get working cleanly. If you are hitting the throw calls, then it is not working. Officially, Addressables is only async. This demo is meant as an example you can use as a starting point to try to build a sync wrapper around it, but it is not complete, and getting it working for your game may not be straightforward. How to make sync loading work for your game is not something we can offer support for.
The problem is that it doesn't wait for the asset to load and check right away if the object.IsDone resulting in a failed to load