|
Post by mattinjersey on Jun 1, 2020 4:56:33 GMT
Hello, I would like to set NavMesh destination separately for each clone. On the Kyle prefab, I have a script that takes care of NavMesh, called cNav. So I tried this:
var spawnedItem=PoolBoss.SpawnInPool(robotKylePrefab, spawnPos, robotKylePrefab.rotation);
thisNav = spawnedItem.GetComponent<cNav>();
DestPos = new Vector3(Random.Range(-50f, 50f), 0f, Random.Range(-50f, 50f));
Debug.Log("DestPos:"+DestPos);
thisNav.xSetPoint(DestPos);
It did not work, though. I guess spawnedItem is not a GameObject, its a transform.
So how to set NavMesh destination on the clone?
Thanks Matt
|
|
|
Post by DarkTonic Dev on Jun 1, 2020 15:56:39 GMT
What am I missing? You can call GetComponent on a Transform too, right? It compiles?
|
|
|
Post by mattinjersey on Jun 1, 2020 22:33:52 GMT
yes you are correct. I found the error- the PoolBoss was calling a function on my prefab before the "start" method on the Prefab had run. So I put the start commands into the function on the prefab. Then it worked OK. Thanks Matt
|
|
|
Post by DarkTonic Dev on Jun 1, 2020 22:53:12 GMT
Yes, Start method is not guaranteed to run before the game object becomes inactive. Any state initialization code you should move out of Start (and Awake if it's there) and into OnSpawned, as the documentation states.
-B
|
|