Extending GameLib with Coroutines


I just tried something that I thought would work and it didn’t… and now I’m confused.

I thought it would be useful to write a coroutine to smoothly interpolate global time dilation to a new value and it made sense that this might live in GameLib. So I wrote my _time_dilation_ramp and noticed that nobody could call it, according to :sk: it didn’t exist.

So I’m thinking GameLib is just UGameplayStatics which is just a bunch of static functions, ah, oops I should have made this a class member instead of an instance member… hmm but now the ide doesn’t allow me to make a class level coroutine, it automatically toggles me back to instance as I’m typing the name of the coroutine.

So now I’m guessing that this is by design and that I never really understood how things work. Can anyone clear things up for me? Mostly just looking for ways to add useful coroutines to some of the standard libs.


That’s right. Coroutines may only be instance not class. Just wasn’t much of a use case for them so it was never implemented. :man_shrugging: Class coroutines certainly could be implemented. It would also add some memory cost to every class.

For now since as you noted all GameLib routines are class methods, you could add them to Mind or Master.

The default Master mind is the target reciever / this for all the code snippets run in the workbench. You can also get access to the Master mind object instance with Master.instance.

Or maybe even better, you could add them to one of the objects that would otherwise be an argument to _time_dilation_ramp(). What are the parameters that you planned to pass to _time_dilation_ramp()?


Yes this makes sense. My prototype was:
(Real target, Real speed : 10.0)

Since global time dilation is world specific, it makes sense that this might live in the World class.


If you use a world object (which makes intuitive sense), you could then use:

@@world._time_dilation_ramp(target speed)

Alternatively, you could use a target time dilation as your object: