Stride Forums Archive

Alternative for the Invoke function of Unity?

5 posts, 6259 views, 2020-03-09 to 2020-03-11

Luktyen_Studios 2020-03-09 #1

Hey, so I came from Unity to Xenko and am a decent Unity C# programmer. So far, I felt like at home when using Xenko. Yet I never really touched timers, as Unity did provide those awesome Invoke functions. Now I come here to ask if there is a similiar feature in Xenko? I would be very thankful if someone would tell me!

tonfilm 2020-03-10 #2

What can you do with that feature? I’m not familiar with that, since I don’t have much experience with unity

Kryptos (Nicolas Musset) 2020-03-11 #3

Last time I heard about it, it was considered an obsolete API and recommended to use coroutines instead.

Anyway what you are looking for could be to use an async method with some Task.Delay() calls.

Such as

public async Task Invoke(Action action, TimeSpan delay)
{
    await Task.Delay(delay);
    action();
}
tonfilm 2020-03-11 #4

Ah, if it’s just for timing, Xenko is much nicer to work with in that regard.

Since Xenko is using the official .NET runtime and you can use latest C# features, async/await is the way to go, as Kryptos said.

Luktyen_Studios 2020-03-11 #5 in reply to #3

Ah, okay, thank you!
I will look into iit and try it out!
Thanks again!