- Home /
Question by
yxyx136 · Apr 19, 2015 at 03:19 PM ·
coroutineclassother script
Unity call couroutine of child object by parent
Hey Guys, I'm trying to call my IEnumerator of my sub class (which isn't a mono behaviour) using the parent class. Here's some code to explain it better: public class ChunkLoadingQueue {
public ChunkManager chunkManager;
List<Vector3i> queue = new List<Vector3i> ();
public GameObject playerGO;
public ChunkLoadingQueue(ChunkManager chunkManager) {
this.chunkManager = chunkManager;
chunkManager.voxelTerrain.StartCoroutine("loadChunksForPlayer");
}
IEnumerator loadChunksForPlayer() {
while(true) {
for (int x = 0; x < chunkManager.chunkData.GetLength(0); x++) {
for (int y = 0; y < chunkManager.chunkData.GetLength(1); y++) {
for (int z = 0; z < chunkManager.chunkData.GetLength(2); z++) {
float distance = Vector3.Distance(new Vector3(x * chunkManager.chunkSize, y * chunkManager.chunkSize, z * chunkManager.chunkSize), playerGO.transform.position);
if (distance < Player.renderDistance) {
if(chunkManager.chunkStates[x, y, z] == (int)ChunkState.None) {
addChunk(x, y, z);
}
}else if (distance > Player.renderDistance) {
if(chunkManager.chunkData[x,y,z] != null){
chunkManager.unloadChunk(x,y,z);
}
}
}
}
}
loadChunk();
yield return null;
}
}}
I'm currently getting this error: Coroutine 'loadChunksForPlayer' couldn't be started!
I've every code i've seen in other threads like creating a function in the mon-behaviour class which calls it etc. but none of them worked. Is it possible to start a coroutine from my "ChunkLoadingQueue" class?
Thanks in advance!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613193514im_/https://answers.unity.com/themes/thub/images/avi.jpg)