I’m running the following code in an Editor script but it’s only instantiating the gameobjects sometimes. After searching for this topic, it seems that the issue is that the Editor would only run this async function when triggering an action. Trying to solve to issue myself has also made me notice that the method starts working after making a script change and the Editor does its usual domain reload / script rebuild.
void SpawnPrefab(ShapeData shapeData)
{
Addressables.LoadAssetsAsync<GameObject>(shapeData.AddressableTags(), obj =>
{
GameObject _newShape = PrefabUtility.InstantiatePrefab(obj) as GameObject;
(Object.targetObject as LevelBuilder).ApplyDataToShape(_newShape, shapeData);
EditorReadParams(_newShape, shapeData);
}, Addressables.MergeMode.Intersection, false);
}
My ideal outcome is to make the instantiation more consistent. To have it immediately instantiate the gameobject without having to trigger an action or domain reload.
The solution people have recommended is to use 1. AssetDatabase or 2. EditorCoroutines.
-
If I were to use AssetDatabase instead how would I get the path to the GameObject? I rely on the Addressable’s labels to fetch the specific GameObject to instantiate.
-
I have imported the EditorCoroutines package and tested it out. It still doesn’t work. I can confirm that the Coroutine is running but the AsyncOperationHandle doesn’t seem to be running. I have checked against it’s PercentCompleted (returning 0), Status (returning None), and GetDownloadStatus.Percent (returning 0).
Edit1 : Unity Editor is 2022.3.9f1 and Addressables package is 1.21.17