I have a material with a flipbook playing 4 frames. So the material goes 0-1-2-3-0-1-2-3 etc. When I press a button the material is applied to a widget and so becomes visible on screen.
The problem I am having is that when I press the button I would like the material to play 0-1-2-3, but it’s as if the flibook in the material is constantly playing somewhere in the background even if not applied. So when I press said button I will not always have the animation going 0-1-2-3 but depending on when I press it, I might see the animation going 2-3-0-1 or 1-2-3-0.
How can I tell the flipbook material to always start from frame 0 when I apply it?
Yeah, I tried that, made dynamic material in blueprint construction script and tried with both a static value and a timeline but is not taking the changes, even if I refer to a parameter collection (tried also with material instance). Tried that in both ingame blueprint and widget blueprint. Something is amiss and I think that’s because I’m referring to a widget. I’m kinda running out of options.
I am not a blueprint guy, but I can tell you what you could do in the material so all you need to do is set up the values in blueprint.
The Animation Phase for the flipbook node can have a scalar parameter of 0-1, just activate it trough a blueprint when the button is pressed and have a lerp in the blueprint output the value of 0 to 1 into that scalar parameter.
I dont know how well versed you are with blueprints, and if you are… like me a total blueprint newb we both need to wait until someone else answers that
the buddy who I always ask to do the blueprints for me is kinda out of town atm. I’ll forward this to the ue4 slack though. ( http://join.unrealslackers.org/ )
I found part of the problem, I was recalling the dynamic material in the construction script in a material variable which did not accept it because what I actually needed was a material ->interface<- variable (as I had thought the widget is making things hard as I can only apply a material interface to it instead of a regular material). The problem now is that a material interface variable cannot be used as target for a “set scalar parameter value”. Now to try and figure out how to do that.
I’ve found an alternate solution for this problem. It’s not a perfect solution, but it worked for my situation where I did not need the animation to be played instantly.
The solution is to wait to make the material visible(or set the material) until it reaches the zero frame in the game timer. The ‘get real time’ node seems to be the same timer as the ‘timer’ node being used inside of the material to cycle through the flipbook. The 3.94…modulo is the length of the animation being played in seconds, and the Shardling variable is just a material variable referencing the material using the flipbook.
The subtraction from the length of the animation(3.94) is to get the remaining time that we need to wait until the time that the zero frame is being displayed, and delay for that long before swapping the material in.
I saw many other threads of a similar nature, but never saw a solution doing something like this so figured it was worth sharing.
@Kevin_Gittens This is a great solution! And very close to being a great way to approach this for the original poster’s problem. A better solution would be to send the time of button press to the material, like this:
By subtracting the current time from the time of button press, it does not matter if the button was pressed at a decimal value, because the result will always start at 0, relative to the button press time. Then, you modulo the value by the animation time so it’s always repeating- in this example from 0-4, with 4 being the total number of desired seconds for the animation to finish playing. Then, we divide the number by 4 to get a 0-1 value for the animation phase.
So as an example:
The button is pressed at 11.3 seconds, this is sent to the material. The Time node is also in game time, so it returns 11.3 seconds. 11.3-11.3 = 0. Once the time node gets to 12.3, aka a full second, the value returned will be 1. 1 modulo 4 is still 1. Then, we divide this number by 4 to get 0.25. In a 4 second animation, at one second we are a quarter of a way through.
As for sending the button press time to the material, it seems like you already have that figured out, but for anyone else viewing this thread, you can do so through Dynamic Material Parameters, Custom Primitive Data, or a Material Parameter Collection- whichever suits your needs the best.