Trying to make a function library with a plugin

Hi! I have a function library that I am updating and using along my projects with very simple but useful functions and I would like to start implementing it as a plugin.

I created a plugin selecting this option:

image

called the plugin as : BlueprintExtraNodes

then I added a test function in the main.h file BlueprintExtraNodes.h:

#pragma once

#include "Modules/ModuleManager.h"

class FBlueprintExtraNodesModule : public IModuleInterface
{
public:

	/** IModuleInterface implementation */
	virtual void StartupModule() override;
	virtual void ShutdownModule() override;

	/* here is my test function */
	UFUNCTION(BlueprintCallable)
	void SayHi()
	{
		GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, FString::Printf(TEXT("Hi!")));
	}
};

I compile without errors but even restarting the project, the test function doesn’t appears in the blueprints:

image

Any help? :slight_smile:
Thanks!
Dany

Do not add your functions in the IModuleInterface thing.

Create a new class (UCLASS) that extends UBlueprintFunctionLibrary, and put your utilities there. Also, your functions should be static in order to be useable anywhere. In many cases, you’ll want to pass a WorldContextObject. Refer to builtin KismetSystemLibrary for examples.

2 Likes

Thanks. Worked

do you know how to get the world object context in the function without including any UObject as input like this BP library function?

image

in the BP it works without the need of plug anything on it

1 Like

I think this is done with the WorldContext meta in UFUNCTION specifiers

 meta=(WorldContext="WorldContextObject")

I added but I still need to put something in the UObject* WorldContextObject parameter of getPlayerController

image

for now works if I plug any object to make a context in the function, but I want to make it work without sending anything just like the BP version

In C++ you can’t. In blueprints the parameter is still there, it’s just hidden most of the time as blueprints are context-aware and know when they can use “Self” as world-context object.

Depending on the use case it is possible to rely on the global pointers to reach a world context, but it is very much not recommended, because you have no way to know which world to use. Also you’ll have to include Engine.h which is a big header file that will slow down intellisense and generate a compile warning.
Example :

UWorld* GetWorld()
{
	auto& WorldContexts = GEngine->GetWorldContexts();
	return (WorldContexts.Num() > 0) ? WorldContexts[0].World() : NULL;
}

Ok! then I will desist and just send any context object from the blueprints.
Thanks again!

Not from the blueprints you don’t have to. I might have misunderstood your issue.

For the automatic pin to work, you need to point the WorldContext meta properly. You point it to “WorldContextObject”, but your variable is named “contextObject”. The meta value must match variable name.