Execute console command from a plugin

Is there a way to execute console command directly from a plugin?

Currently I’m executing console command from the World Blueprint, but I want to move this functionality to the plugin.

Firstly, be careful about relying on Console Execution - as most of the console (if not all) functionality gets stripped in Shipping builds! Also, writing C++ code that relies on console execution is preferred to be avoided, as per this forum post.

Now, that said, and also from the Forum post (put here for ease/posterity), you can do it like so:

GetWorld()->Exec(GetWorld(), TEXT("MyAwesomeConsoleCommand X Y Z"));

That’s simply the Exec() function from the UWorld class. GetWorld() is a global getter for the current world. You might also want to check it’s valid before calling it, something like:

UWorld* World = GetWorld();

if( World != nullptr )
    World->Exec(GetWorld(), TEXT("MyAwesomeConsoleCommand X Y Z"));


Can you let me know what is the World and getWorld() in this fuction.

I am a new guy who wants to run blueprint node by C++ language.

Thank you so much.

If you click on the UWorld link in the above post, it’ll take you to the documentation about that. And as for GetWorld(), it’s a function that every AActor has that will return the World that it is spawned within.