[ad_1]

I have a game I am developing in Unity where AI is doing large calculations when it is its turn. It searches the position to depth 1, then 2, then 3 etc. Between each depth I want to Instantaite a Gameobject with info about the depth to UI. The problem is that nothing happens until the AI is completely finished, then all items are added at once. Here is some code to explain better:

private void AIMakeMove()
{
    for (int currentDepth = 1; currentDepth < maxDepth + 1; currentDepth++)
    {
        SearchPosition(currentDepth);
    }
}
 
private void SearchPosition(int _currentDepth)
{
    // Search the position to the given depth
    score = Negamax(_currentDepth);
 
     // Print things   PROBLEM HERE
    GameObject printItem = Instantiate(printItemPrefab, printItemParent.transform);
    Debug.Log(_currentDepth);
}

I also tried just a simple Debug.Log instead of Instantiate but same thing happens then, all prints to console happens after the AI is done with its thinking process.

Why is my UI not updating with information? I tell it to create some things after it run the first iteration with depth 0 but it skips this step and goes on depth 2 instead. Can someone please let me know how to get information out between each depth?

[ad_2]