Hello
I get the feeling that I’m trying to do something rather strange here, I will do my best to describe it.
All of the art assets I’m using are in the form of .png files and resemble a sprite sheet. I have no issues pulling this in and either extracting individual materials from it via UV or creating flipbooks from it in the editor. In-game, these are typically applied to voxel-like volumes.
For example, I have a sheet that contains a number of states a door may be in - closed, open, a few frames of opening and a few frames of closing. It is trivial to take a single-frame image and create a material from it which can then be applied to meshes, however getting it to animate is really stretching my brain out. Here’s what I’ve tried and the issues I eventually ran into:
- Load the entire sheet in to a material and create a MaterialInstanceDynamic. Using UVs, make each cell in the sheet accessible with a single index. Then, define an animation as a starting frame index, an ending frame index and a framerate. Now for the disgusting bit: Queue up a bunch of calls to the World TimerManager telling it to invoke a lambda, upon each invokation increment the frame index, while setting the delay on the timer based on the desired framerate. Make one final call instructing the material instance dynamic to sit on a single index for the final state.
Eg. Door is closed
Queue first frame of opening animation for after eg. 0.2 seconds
Queue the next frame for after eg. 0.4 seconds
Queue the next frame for after eg. 0.6 seconds
…etc.
Queue the final state setting for after eg. 1.2 seconds, or however long the whole thing should take
Result: It seemed to skip the entire animation and skip to the final state. It also made me physically sick to write, it felt wrong and I can see it leading to some awful fiddling with edge cases in the not-distant future
- Enable Paper2D and do it with Flipbooks. I guess this would take the form of having a flipbook for each state of open (one frame), opening (a few frames), closed (one frame), closing (a few frames) assigned at the blueprint and reassigning the components on the actor to whichever state it had to be in, so something like:
Trigger the door to open
Switch from the closed state flipbook to the opening state flipbook
When it has played once switch to the opened state flipbook (and set other state info like collision etc)
I guess this might work if I read the framerate and number of frames and calculated the total run time, then fed that into a world timer set to set it to its final state.
Result: It feels similarly uncomfortable using the world timer in this way and my senses are telling me this too is wrong.
Does anyone have any hints for a more sensible approach to this? I’m still getting into Unreal and don’t have full perspective on what should be done in editor/blueprints vs. what should be done in code, and also lack the general knowledge of what sort of features in either may be a good lead for this.
I should also add that there are many of these doors, and the game should not lock up while they are opening.
Many thanks in advance