UE4 cooking from cmd

I want to package the game but I don’t like to open UE4 Editor for this.

Is there any CLI for this?

To access the cooking functionality (apart from many other useful tools) you have to use the so called Commandlets. There are plenty of commandlets in the engine (Commandlets | Unreal Engine Documentation).

The cooking commandlet has quite nice documentation: Cooking Content in Unreal Engine | Unreal Engine Documentation

In short you just run it like (commands taken from the documentation):

UE4Editor.exe <GameName or uproject> -run=cook -targetplatform=<Plat1>+<Plat2> [-cookonthefly] [-iterate] [-map=<Map1>+<Map2>]
UE4Editor-Cmd.exe <GameName> -run=cook -targetplatform=<Plat1>+<Plat2> [-cookonthefly] [-iterate] [-map=<Map1>+<Map2>]

Creating your own commandlets is also a very interesting thing.

Can you elaborate on how to create AND execute your own commandlet? I can’t find any substantive documentation or examples.

To create your own commandlets you just have to create a class that inherits from UCommandlet and at-least implement the main method. Nameing the commandlet is also important because it dictates the way to run it (like the cook example.

For example creating a basic commandlet would be adding the following class definition into a header file:

#pragma once
#include "Commandlets/Commandlet.h"
#include "NewActionCommandlet.generated.h"

UCLASS()
class UNewActionCommandlet
	: public UCommandlet
{
	GENERATED_UCLASS_BODY()

public:

	// Begin UCommandlet Interface

	virtual int32 Main(const FString& CmdLineParams) override;
	
	// End UCommandlet Interface
}

As you can see the name of the commandlet is UNewActionCommandlet, so to run it we just have to pass NewAction into the commandline:

UE4Editor.exe <GameName or uproject> -run=NewAction

You can add a commandlet into your game module, a plugin, your own engine module or just adding it where the engine ones are placed.

Cheers,
Moss

1 Like

Awesome, thanks!

Do you still have issues? Just to make sure you resolve the issue (accept the answer) so it will help others too.

Moss,

I am having an issue. I would like to run the UCookCommandlet from within my EditorModule. Is this possible?

I am getting an external linker error from this:

UCookCommandlet* cookCommandlet = NewObject();

It is saying:

error LNK2019: unresolved external symbol “private: static class UClass * __cdecl UCookCommandlet::GetPrivateStaticClass(wchar_t const *)” (?GetPrivateStaticClass@UCookCommandlet@@CAPEAVUClass@@PEB_W@Z)

Any ideas?

No can not directly run a commandlet from within the editor. But you can just execute a new process from the editor. Have a look at:

static bool RunCommandInternal(const FString& InCommand, const TArray<FString>& InFiles, const TArray<FString>& InParameters, FString& OutResults, TArray<FString>& OutErrorMessages, const FString& UserName, const FString& Password)

Within SubversionSourceControlUtils.cpp, it uses

FPlatformProcess::ExecProcess

to execute the svn binary.

Another way would be to ‘CookOnTheFly’ (just search for the term and you will find plenty of code). It can be launched from a session and might be what you are looking for.

Cheers,
Moss

ExecProcess was exactly what I needed, thanks so much!

If you issues are resolved could you accept the answer to help others?

Done, Thank you for great answer!

i need to cook only one single map(contains only bsp brush objects) over and over.
and then pak it.

for paking i am using this command:

J:\4.11_Cpp\Engine\Binaries\Win64\UnrealPak.exe
J:\UnrealProjects\umapWithChair_noCook4.pak
-create=J:\UnrealProjects\cookList.txt

where cookList.txt contains list of files and corresponding mount points.

like that dos command is there any way like that to cook only 2/3 specific files?
i dont want to run whole cooking process because of 1/2 file .

got it:
J:\4.11_Cpp\Engine\Binaries\Win64\UE4Editor-cmd J:\UnrealProjects\pak_4_11_p2\pak_4_11_p1.uproject -run=cook -targetplatform=WindowsNoEditor -map=pakLevelXXXXXX.umap