How to create custom console command in blueprint?

Is there a way to add console commands using blueprint, or is that a C+±only sort of thing? I want to add a command that adds a particular widget to the viewport.

P.S. I know this question has been asked before, but no one actually answered it.

Hi!

Pure console comand you can create only in C++.

For blueprint version, you can create Custom Event. For example, myCustomEvent in Level Blueprint, and in console type:

ce myCustomEvent

3 Likes

would that functionality break in shipping builds? or would it just get rid of the console command prompt, but still allow the console command BP nodes to work?

My solution…

I did a Exec catcher in our class for GameInstance.

Our game instance blueprint has a game instance child class it inherits from so it is…

TDLGameInstanceBP==>TDLGameInstance==>GameInstance

being…
The Blue Print ==> The C++ we wrote ==> The internal Unreal Engine C++ GameInstance class.

We register our “tdl” console commands, then catch them, and relay them up to the blueprint TDLGameInstanceBP.

In the blueprint we parse out the arguments.

So in TDLGameInstance.h we have…

#pragma once

#include "Engine/GameInstance.h"
#include "tdlGameInstance.generated.h"

/**
 * 
 */
UCLASS()
class TDL_API UtdlGameInstance : public UGameInstance
{
	GENERATED_BODY()

public:
	UtdlGameInstance(const FObjectInitializer & ObjectInitializer);

	// Begin FExec Interface
	bool Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Out) override;
	// End FExec Interface

};

and in tdlGameInstance.cpp we have…

#include "tdl.h"
#include "tdlGameInstance.h"

UtdlGameInstance::UtdlGameInstance(const FObjectInitializer & ObjectInitializer) :
	UGameInstance(ObjectInitializer )
{
	if (!IConsoleManager::Get().IsNameRegistered(TEXT("TDL kill zeds")))
	{
		IConsoleManager::Get().RegisterConsoleCommand(TEXT("TDL kill zeds"), TEXT("TDL Commands"), ECVF_Cheat);
	}
}

char funcTDLGameInstanceCallBuf[1024];
bool UtdlGameInstance::Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Out)
{
	bool bHandled = false;

	// Ignore any execs that don't start with tdl
	if (FParse::Command(&Cmd, TEXT("TDL")))
	{
		FString TestStr = FString(Cmd);
		_snprintf(funcTDLGameInstanceCallBuf, sizeof(funcTDLGameInstanceCallBuf), "tdlConsoleCommand %s", TCHAR_TO_ANSI( *TestStr ));

		FOutputDeviceNull ar;
		CallFunctionByNameWithArguments(ANSI_TO_TCHAR(funcTDLGameInstanceCallBuf), ar, NULL, true);

		return true;
	}
	return Super::Exec(InWorld, Cmd, Out);
}

And the TDLGameInstanceBP looks like…

Now after that final Print Text node we can put a Split on the command arg and do something with it.