Page 1 of 1

FSM Start() behavior array-serialization bug

Posted: 2017/07/06 22:48
by igor
Hi

When starting game, FSMInternal invokes state.EnableState( true,true );

It in turn, calls behaviour.OnStateAwake()
and behaviour.OnStateBegin();

Problem:
I have script on first state. It always gets OnStateAwake() + OnStateBegin() during FSMInternal.Start()
My script has [SerializeField] GameObject[] prefabArray;

On first frame, I get exception from the script - it has empty array, because it was enabled during OnStateBegin() :(
Unity didn't have time yet to load array with data

Next frame, unity serialized the array with prefabs, and everything is ok :)

Re: FSM Start() behavior array-serialization bug

Posted: 2017/07/06 23:00
by igor

Re: FSM Start() behavior array-serialization bug

Posted: 2017/07/07 00:39
by caitsithware
Hi.

I checked the behavior of the problem, but I could not reproduce it.

Checking environment:
Unity 5.6.2f1
Arbor 2.1.2

Method for checking:
  • Create a new project with Unity 5.6.2f1.
  • Imported Arbor 2.1.2.
  • Create script below.

    Code: Select all

    using UnityEngine;
    using System.Collections.Generic;
    using Arbor;
    
    public class TestStartSerialize : StateBehaviour
    {
    	[SerializeField] List<GameObject> prefabs;
    	
    	// Use this for enter state
    	public override void OnStateBegin()
    	{
    		if (prefabs != null)
    		{
    			Debug.Log("OnStateBegin : " + prefabs.Count);
    		}
    		else
    		{
    			Debug.LogError("OnStateBegin : prefabs is null");
    		}
    	}
    }
    
  • Attach & set to Start state and execute.
2017-07-07_09-34-15.png
2017-07-07_09-34-15.png (42.35 KiB) Viewed 4768 times
If there is any difference in the checking method, please let me know.

Re: FSM Start() behavior array-serialization bug

Posted: 2018/02/28 20:34
by igor
Thank you!

I've solved the problem

It was because I had 2 FSM with same names "myAbilitiesFSM"