Swapping animations at runtime

Place to get help with not working mods / modding interface.
danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 95
Joined: Thu May 18, 2017 2:22 pm
Contact:

Swapping animations at runtime

Post by danielbrauer »

Is it currently impossible to swap an entity's animation at runtime? What I've read so far leads me to believe it's not possible. I can specify (for instance) the lab's on_animation in the data stage, but it's inaccessible after that.

I can think of two reasons for this:
  • There is a lot of work that goes into creating actual, renderable animations from the table structures defined in the data phase. This work is done once during load, so you can't make any animations at runtime. I guess the only way around this would be if you could pre-generate a set of animations in data, and then swap references to them later.
  • Prototypes can't change at runtime, partly because this would have complex and inefficient implications for every instance.
If you can't generate animations at runtime, and you can't assign them to prototypes at runtime either, what sort of workarounds would be possible? The only thing I can think of is:
  • Creating multiple copies of a prototype, each with one of the animation variants I want. Then swap entities out for other ones entirely instead of just trying to swap their animations. I could see this being a potentially computationally intensive task (that scales with the number of entities), and there might be some work involved in carrying over each entity's inventory to that of its replacement.
Bilka
Factorio Staff
Factorio Staff
Posts: 3470
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Swapping animations at runtime

Post by Bilka »

Create multiple "animation" prototypes and draw them whenever you wish using the script rendering.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 95
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Swapping animations at runtime

Post by danielbrauer »

Bilka wrote: Mon Mar 11, 2019 2:07 pm Create multiple "animation" prototypes and draw them whenever you wish using the script rendering.
Thanks, that makes sense. In the specific case of the lab on_animation, though, any code I write to do this will be much less efficient and more complicated than changing the animation strips in the data phase, right?

I guess maybe this wouldn't be so bad if I can restrict it to just the labs that are on-screen.
Post Reply

Return to “Modding help”