How to get WorldContextObject inside a C++ BP Function Library?

Hey guys,

I’m wanting to access a couple of functions. In this case, Get World Delta Seconds. I’ve been looking at the documentation for the process for that but don’t think I’m getting the right gist of it.

From a BP perspective:

257084-worldcontextobject.jpg

How can I make a proper reference to this function? (More specifically, so that Get World Context is the function’s own World Context)
It would be helpful to know what I need to include in the Header and then the construction script.

Thanks!

World Context Object its any object that appear in current world. Its can be almost anything (PC, Game Mode, Actors & anything like that). You can use any UObject for that

    UFUNCTION(BlueprintCallable, BlueprintPure, Category = "TestOnly")
    static float GetWorldDeltaSeconds(UObject * WorldContextObject)
   {  
return WorldContextObject->GetWorld()->GetDeltaSeconds();  
 }
2 Likes

In the UFUNCTION Macro you have a Metadata Specifier WorldContext=“Parameter” and you can use it to act as your parameter.

In your .h file

 UFUNCTION(BlueprintPure, Category = "Test", meta = (WorldContext = "WorldContextObject")) 
static float GetWorldDeltaSeconds(const UObject* WorldContextObject);

In your .cpp file

 float UMyBlueprintFunctionLibrary::GetWorldDeltaSeconds(const UObject* WorldContext)
 { 	
    return WorldContext->GetWorld()->GetDeltaSeconds();
 }

You can include ([UObject | Unreal Engine 5.2 Documentation][1])

include “Runtime/CoreUObject/Public/UObject/NoExportTypes.h”

You will get this result

257100-result.png

1 Like

That worked! Thank you!
Furthermore, I got curious as to how to assign them their internal Object value. This answer helped with defining that internal sector: