Programming Limitations to Unity - Coroutine - soey_0@hotmail.com

When my program runs in this sequence l seem to not find a game object in my object hirerachy at run time.

void Update() {
StartCoroutine(run_num_count_routine(num));
}
void IEnumerator run_num_count_routine(int a_num)
{
while(!pause_times_tbl_run)
{
chg_a_num_UI();
}
}
void chg_a_num_UI()
{
find game object // errror can not find game object
// from this function
}

But when l run find game object in say update rather than in the chg_a_num_UI() function it does not work.
Any Sugestions.
Joe. email: soey_0@hotmail.com

Welcome to the forums.

I’m assuming your code here is just pseudocode, right? Because if that’s real code, it’s pretty obvious why it would fail. :stuck_out_tongue:

It would be best if you shared your actual code so we can see what’s going on. Also be sure to use code tags to make it easier on us for reading.

That code would not even compile. For one, there is no return statement in the IEnumerator. So if we can’t see the real code you are using, I think we won’t be able to help you.

1 Like

I’m guessing you tried to say that it does work outside the coroutine. Haven’t heard of something like that, but still I don’t use FindObject. I recommend you use a

public List<GameObject> nums = new List<GameObject>(0);

And assign them on the editor, rather than finding them by code.

1 Like

And just for future reference, I’m doubting that anyone is going to be emailing you… the idea is to reply to the thread… in the thread :wink:

2 Likes

When someone puts their email in their thread title it means they have no intention of coming back, so you shouldn’t bother replying.

4 Likes

Does not need a moderator. Here, the forum is quietly self-governing :slight_smile:

The code does comple, its not pseudocode l just left some of the code out.

Thanks for the people that have said some comments.
I did not expect any one to reply.
But when l get to void chg_a_num_UI() find game object does not find the game object when l do a find game object out side of this function it works.

Is there any limitation in the unity system whey it will not work.

Also if there are 2 game objects that are the same which one will it pick up. One game objects is in an array, and another is in the scene.

Would that be the problem?

https://forum.unity.com/

Nope.

That is going to make it virtually impossible for folks to help you out, as there is a lot going on there, and lot of places for things to wrong Without the full, relevant code, it would just be wild guesses. If you want help, you are going to need to provide more information.

For example, you are passing an int into the coroutine that doesn’t appear to be used. If it is used, it would be helpful to know for what, if it is a dependency that is causing failure. You also have a bool conditional in a while loop, but nothing explaining what it does, what it is set to, or when it is flipped. If pause_times_tbl_run is true, your other function will never get called. Alternately, it may be getting called all the time. Also you are calling a coroutine from update that contains a while loop. That is most likely overkill, in almost any instance. Update is called ever frame, you are starting a new looping coroutine 60+ times a second, if there is a find in there, it’s not going to go well. Find can be slow, if you are calling it thousands of times a second, things are going get backed up.

Find will only find named active gameobjects in the hierarchy, it doesn’t search arrays or other things. If there are more than one with the same name, and you are not supplying a path, it will return the first one it finds.

2 Likes

That means it is pseudocode. It doesn’t work. :slight_smile:

2 Likes