In my game I am using a class which inherits from UBlueprintFunctionLibrary where I have defined a couple of static functions .I need to call non-static functions while inside the static ones and also use static variables, but I have no idea how to do it since I can’t get an instance of the blueprint function library class. I tried with
Where MyFunction is a non-static function. However the engine crashes at the first line with the error
Fatal error: [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectGlobals.cpp] [Line: 3193] FObjectInitializer::Get() can only be used inside of UObject-derived class
Is there any solution that isn’t declaring every function and variable as static?
UBlueprintFunctionLibrary class is dedicated to bluerpint node function that don’t fit to any other class or original classes are not in reflection system (most notable example is FMath). UBlueprintFunctionLibrary don’t have any code, BlueprintCallable and BlueprintPure static or non-static works the same anywhere. so it’s existence is purly for organization
UBlueprintFunctionLibrary should not be used for non-static function, if you do then you probably doing something wrong. First think if you really need to use UBlueprintFunctionLibrary, remember BlueprintCallable can used anywhere, and non-static function should be in class relevant to it, there no issue of having static functions on other class either if there code is relevant to hosting class, it’s purely your choose and organization matter.
If you have no access class you want to operate in the function to declare function in it, pass it as a argument insted.
If you need access UWorld, there actually special way to do it in static function without need of any extra pins or other hacks, you declare function like this:
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
WorldContextObject wont be visible in the node, blueprint system will automatically pass proper object. From UWorld you can access many global objects which also allows you to avoid making pins to pass them.