Programmatically creating a runtimeAnimationController for Tilemap animations

I am building a Tiled.org TMX parser (I know there are ones that exist and I’m using one of them, but I’m extending it to allow for Tiled animations) and I’ve run into a problem where I cannot programmatically create an Animation Controller.

Let’s say I have the following snippet of code:

Animator newAnimator = (Animator)tilePrefabObj.AddComponent ();
newAnimator.runtimeAnimatorController = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate (Resources.Load (“Artwork/Sprites/sprite_0”));

SpriteRenderer sr = tilePrefabObj.AddComponent ();
SourceData sd = gid2sprite [tileGID.Value];
Sprite source = (Sprite)sprites.First (s => s.name.Equals (sd.spriteName));

sr.sprite = source;
sr.sortingOrder = 0;
sr.color = new Color (1, 1, 1, 1.0f);

This works just fine and I can see that my prefab contains the Animator component and that its Runtime Animation Controller is set to the sprite_0 prefab.

What if I want to reference multiple sprites and create an Animation Controller programmatically and set the runtimeAnimationController to that instead – rather than use an existing Resource that already exists?

I can’t find any documentation on creating a simple Animation Controller that contains a handful of different sprites in order to create an animated sprite.

Hi

Unfortunately, this cannot be done at runtime at the moment. However, it is possible to do within Editor code