Allow Blueprints of class "Object" to access Timers and BP Libraries.

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.

The base class would have to be in C++. Create a new C++ class based on UObject, add the GetWorld() logic, then inherit from that in BP. No other way unfortunately.

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.

Hey @DamirH and @TheJamsh. How are you?

Well, I’ve tried to reproduce the steps you mentioned but it seems my BlueprintFunctionLibrary’s functions are still not recognizable from the Actions Menu.

Pretty much I:

  • Created a C++ class that inherits from **public UObject **- let’s call it “ParentObject”;
  • Went to my editor and reparented (successfully) my Object Blueprint Class (let’s call it “ChildObject”) to be the one I created on C++ (ParentObject);
  • Added the following code to my ParentObject.h:

virtual class UWorld* GetWorld() const override;

  • Then, at my ParentObject.cpp:

UWorld* UParentObject::GetWorld() const {
  return this->GetOuter()->GetWorld();

It turns out that when I right+click my Grid in the Editor, it still doesn’t show any Functions/Events that depend on the WorldContext, such as my BluperintFunctionLibrary functions or timers.

Any ideas on what it could be?

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:

UFUNCTION(BlueprintPure, Category = "Some Function", meta = (WorldContext = "WorldContextObject"))
static USomething* GetSomething(const UObject* WorldContextObject);