SetDestination fails with delay and baked NavMesh

I have a terrain and NavMeshSurface that has been correctly baked.
I turned a script into a Coroutine with 5 seconds delay which spawns humans and puts them by raycasting on the ground.
I place Human on it, and I tell it SetDestination, then I get an error:
“SetDestination” can only be called on an active agent that has been placed on a NavMesh.

void Z()
        {
            Vector3 pos = transform.position;

            if (Physics.Raycast(new Vector3(pos.x, 999, pos.z), Vector3.down, out RaycastHit hit, Mathf.Infinity, StaticX.layerMask))
            {
                transform.position = hit.point;
                transform.GetComponent<MyHuman>().agent.SetDestination(Vector3.zero);                //                       "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
            }
            else
            {
                // Not invoked
            }
        }

The position is valid. Human GameObject hits the ground. Click the object paints the floor blue (as a validly baked mesh). I rebuilt it many times. What is possibly going wrong?

It’s placed on a valid mesh and the human has their NavMeshAgent enabled and put onto the object.

Are you telling the prefab to go somewhere instead of the instantiated copy of the prefab? Doing so will give this error.

No. The human is first created using Instantiate(humanPrefab) and then I use GetComponent to get its script, then I position it, then I run “SetDestination” and that’s when the error comes. The GameObject isn’t a prefab, its an instantiated copy.

After testing I finally found out whats happening. If the GameObject has been spawned outside NavMesh it will fail SetDestination, even if you set its position . I even turned function into coroutine, set position, waited 5 seconds and then it fails, but if you see create the object close enough to the NavMesh and then move it to position and then SetDestination, then it all works. Meaning that the object must be spawned on a NavMesh, no questions asked. Which brings the question, is there a way to override it without setting its direct position upon spawn?

Without knowing or trying it myself, but simply looking at the Agent API, I suspect perhaps this will be useful:

https://docs.unity3d.com/ScriptReference/AI.NavMeshAgent-updatePosition.html

There’s one for rotation as well.