Hi,
I am trying to intantiate multiple instances of the prefab generated through SpriterDotNet plugin for unity.
This is my code :
public GameObject enemyPrefab; // The Prefab exported from Spriter goes here
public void Start ()
{
GameObject obj = Instantiate(enemyPrefab) as GameObject;
obj.transform.parent = transform;
}
The prefab is getting instantiated and also gets parented to the GameObject, however, i am getting an error while trying to access the UnitySpriterAnimator object
Please find the code below :
public UnitySpriterAnimator animator;
//Written inside start
if (animator == null)
{
animator = gameObject.GetComponentInChildren<SpriterDotNetBehaviour>().Animator;
animator.EventTriggered += e => Debug.Log("Event Triggered. Source: " + animator.CurrentAnimation.Name + ". Value: " + e);
}
I got the following error while trying to use animator
NullReferenceException: Object reference not set to an instance of an object
It works fine if i get the reference for animator inside Update. Please let me know if this is an expected behavior. I am new to Unity and Spriter, I apologize in advance if my question is stupid