For loop executes partially!
Hey guys, In one of my scripts, I call the below function once through a Start() method in some another script.
private void ChangeState()
{
for(int i = 0;i<statesToChange.Length;i++)
{
// statesToChange[i].SetState(AIControl.States.Convoy, statesToChange[i]);
if(stateToChangeTo == AIControl.States.GoTo)
{
FriendlyAIPlaneControl Leader = statesToChange[i].GetComponent<FriendlyAIPlaneControl>();
Leader.GoToPosition = positionToGoToForEnemy.position;
}
statesToChange[i].currentState = stateToChangeTo;
Debug.Log("1");
}
Debug.Log("2");
isActive = false;
ParentScript.CurrentObjective = this.NextObjective;
ParentScript.CurrentObjective.ObjectiveStart();
}
This line
statesToChange[i].currentState = stateToChangeTo;
changes the state of a state machine of one of my ships.
Interesting thing is that the debug.log("1") does not execute at all. But it executes if the function is called through Update(). Or, even if it is placed before the state changing statement. Do for loops need to be called repeatedly to complete all the loops? And even if I call it through Update(), 2 does not get printed. I suspect to be the problem of the FSM framework, but few days ago, it was working fine. Any help will be appreciated, I wasted half a day on this!
I'm using FSM framework from UnityGems.
Thanks!
please format ALL of your code.
this following line is incomplete - have you posted ALL of the code?
private void ChangeState() { for(int i = 0;i
Your answer
![](https://koobas.hobune.stream/wayback/20220612055802im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Spawning/Destroying objects inproperly 0 Answers
For loop comparing two different objects appears to not be running 1 Answer
Bizzare error with for loop and tex2D in HLSL shader 1 Answer
Creating triangles around a mesh using an array of vertices 1 Answer
How can I not load all this map generation at once? 0 Answers