Skip to content

Commit

Permalink
fix: Prefab Requests are returned early (#521)
Browse files Browse the repository at this point in the history
* Fixed a bug where prefab request is yielded early

* Fixed false null prefab factory logs

* Improved the logs for InitPrefabAsync
  • Loading branch information
Metious authored Jan 1, 2024
1 parent d296709 commit 15d6db1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Nautilus/Assets/ModPrefabRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class ModPrefabRequest: IPrefabRequest

private readonly PrefabInfo prefabInfo;

private CoroutineTask<GameObject> task;
private IEnumerator task;

private TaskResult<GameObject> taskResult;

Expand All @@ -37,7 +37,7 @@ private void Init()
return;
}

task = new CoroutineTask<GameObject>(PrefabHandler.GetPrefabAsync(taskResult, prefabInfo, factory), taskResult);
task = PrefabHandler.GetPrefabAsync(taskResult, prefabInfo, factory);
}

public object Current
Expand Down Expand Up @@ -66,14 +66,12 @@ public bool MoveNext()

public void Reset()
{
Init();
task.Reset();
Done = false;
}

public void Release()
{
ModPrefabCache.RemovePrefabFromCache(prefabInfo.ClassID);
taskResult = null;
task = null;
Done = false;
Expand Down
6 changes: 6 additions & 0 deletions Nautilus/Handlers/PrefabHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ internal static IEnumerator GetPrefabAsync(TaskResult<GameObject> gameObject, Pr

private static IEnumerator InitPrefabAsync(TaskResult<GameObject> gameObject, PrefabInfo info, PrefabFactoryAsync prefabFactory)
{
if (prefabFactory == null)
{
InternalLogger.Error($"PrefabHandler: Prefab Factory for {info.ClassID} is null!");
yield break;
}

yield return prefabFactory(gameObject);

var obj = gameObject.Get();
Expand Down

0 comments on commit 15d6db1

Please sign in to comment.