Function Update is not being called when object have a parent
Hi,
I'm getting a bit stuck with my AI system and I encounter a really weird problem, I've been using Unity for many years but I never encounter this.
Basically, I'm making a procedural game where almost everything is made during runtime including navmesh and Spawners :
My spawners have a script attached which allows them to spawn the animals, this script works perfectly fine, here are the two main lines used to spawn AI :
GameObject randomAnimalPrefab = Instantiate(holderScript.animalsPrefab[3], new Vector3(transform.position.x, transform.position.y + 0.2f, transform.position.z), Quaternion.identity);
randomAnimalPrefab.transform.SetParent(transform);
As you can see I instantiate my animal (animalsPrefab[3]) and I then attach the spawned object to the transform of this script which is "Spawner(Clone)" on the last screenshot.
Now here is the problem : My Animals (let's say AI) have a script which allows them to move on the terrain based on a runtime bake. The script is a bit long but here is the important line which is in the Update function :
transform.position = Vector3.MoveTowards(transform.position, target, movementSpeed);
In theory, this line is supposed to move my AI to a randomly generated target on the terrain (don't ask why I'm not using SetDestination with agent, the proceduraly generated terrains hardly allows that). The problem is that this line and the whole Update function is not read when my AI has a parent.
BUT
When I move my AI out of the "Spawner(Clone)" parent it works perfectly fine. Here is a video to explain this more in details :
Notes :
• All my scripts derive from MonoBehaviour
• All the parents objects are active so the Update function should be running
• I used a Debug.Log in the update function but it is never read as long as my AI has a parent.
• I tried to use "localPosition" instead of "Position" without success but the problem is maybe linked to that
TLDR : My Update Function is never called when my Object has a parent.
If you post the code maybe... we are not magicians.
PD: beeing a child or a parent is irrelevant for execution of Update()
Your answer
Follow this Question
Related Questions
orbit gravity, 0 Answers
Runtime Navmesh only getting edges of mesh 0 Answers
Creating NavMeshAgent types at runtime 0 Answers