Download

Get game time from material

I am spawning widgets on the screen at random intervals, and would like the material that the widgets are using to fade out once created. The problem is that I have no way to know how much time has passed since the material instance has been created, nor do I have a proper way to get game time within the material. The ‘Time’ node is the time since the engine(If playing in editor)/game(If playing in stand-alone) has started, but greatly differs in value from any of the Blueprint nodes that I have available in a Blueprint graph.

What I originally attempted to do was pass in the creation time of the material instance through a scalar parameter, and subtract that from the Time value:
8c62025c29f892d35050017692f398e48d5d3d7b.jpeg

This did not work, as there is no way to get the same value that Time provides, through Blueprints, in order to set the parameter. Answer-hub threads that I have read reference the ‘Get Real Time in Seconds’ Blueprint node, citing that it matches the time provided by the Time node in the material graph, though that is not the case for me (Tested in Standalone game, and editor preview).

I have too many objects to drive the opacity with a timeline, or in any other way on tick. What am I doing wrong?

i would try to approach this problem with the Panner node and minmax the result, while putting it into the opacity of a lerp.

I’m not sure I understand. Panner uses time, meaning it would have a random starting point. I am unable to offset that starting point due to me not being able to properly determine the time upon creation.

You need the blueprint of the actor of the object that contains the material to collaborate with the material.
It can play a timeline, or just calculate a value in Tick(), but that value needs to be provided to the material manually.
Create a timeline, start it, and in Tick(), update the shader parameter with the value of the timeline.

The Time material input is indeed equals the View.RealTime, which is get passed by the engine in each tick. Enable the r.DisplayInternals 1 so you can debug the Real time parameter, and just pull an actor that prints the result of the Get Real Time Seconds() node. Hit play and they are match. Even, if you pause the game (which will affect the world time only) then hit play again, the actor will continue to print the proper real time.

There is however some inconsistency here which i can’t explain just yet, when you add actors manually while in the editor, the get real time seconds() node you access in the Constructor will give you a time that is way behind the real time shown on the DisplayInternals debug panel.

This is not the case if you spawn a new actor from the game (pie), the real time will match for those actors, and the material instance input you set from the grts() node will be a match, and your computation will just work.

03e6198edf56f2c536e1cccb8b78f5ddc29f40b0.jpeg

The semi transparent spheres are about to disappear, while the opaque ones are just spawned. The red sphere at the most left was the actor i placed manually in the editor, and it have a misaligned realtime value because i set it from the constructor.

It seems you’re better to set the mi parameter at the event BeginPlay which will set the proper realtime value in both cases (spawned/placed actor) and your equation should work pretty well. It does for me in 4.14.1.

While this is what I ultimately wanted to avoid, I did end up doing this due to later requirements I needed to fulfill :stuck_out_tongue:

Thanks for the info! If there is anything that gets me, it is cases like these where there are inconsistencies.

We have a material param collection that is used globally, on a single tick it is updated with the game time.

Now any material that needs to sync up with game time can.

For a progress bar that animates without a tick or a timer, we would on start the timer by supplying a start and end time to the material

Just a heads up for future googlers - It seems that in 4.24 at least, the Time node is returning WorldTime not RealTime.