I don’t know if it is intended to not be this way but it would be really cool if it could be added. Just allow us to use all timer, delay functions inside “object” blueprints, and functions from blueprint libraries.
If it is intended to work the way it is, then nevermind and move on.
You can already do this. In your custom UObject class just implement
virtual class UWorld* GetWorld() const override;
Since UObject’s aren’t necessarily actors or exist in the world, they need a way to provide the world context to timers etc. It is up to you how to implement this function. In my example, my spells are UObjects and when I spawn them I provide them with the actor who casted them, so GetWorld() just returns MyOwnerActor->GetWorld().
Can i do this to an allready existing Object class, that i created from blueprints originally? I am in the same boat as you, i am using objects for the spells, but i can’t use timers, ray casts, bpls, etc. I just need to do that. I also pass the caster as the outer when i construct them.
Edit: I am not good in C, but with a proper walk through i can do this if it is possible to an allready existing class, originally made from blueprints.
Be aware that implementing this wrongly could lead to noticeable lag when you call world context dependant function from this object for the first time per engine start. From my experience, fastest implementation is to take world context from specified object that already knows it - exactly the way DamirH is doing it. I prefer to use something more global than casting actor to do it, though - actors could go away while spell is still running and cause unexpected behaviour.
Delays are managed by the Latent Action Manager which is pretty similar to the Timer Manager and also bound to the world, so it too requires World access.
Also it’s important to note that the GetWorld() function also needs to return a valid world when opened in the Blueprint Editor as well (even if it’s just the Blueprint viewport world). The Editor uses the GetWorld() function to determine if you’re able to access world-based functions and variables as well (e.g, Getting World Time etc.)
I believe Actor Components do this by casting their Outer to a World when they don’t have a valid owning actor.
Blueprint Function Libraries can’t have worlds of their own really, and their functions are usually static so a world context object must always be provided anyway.
That said, you can add meta = (CallableWithoutWorldContext)) to a UFUNCTION to show it in an object with no world context. Also, declaring functions like this will auto-fill the pin when required, or show the pin when needed: