Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

Launching Map with command line ?!


I want to launch a Map of my shipped Game from command line. I'm using this pattern for the command line : MyGame.exe /Game/Maps/MyMap (https://docs.unrealengine.com/latest/INT/Programming/Basics/CommandLineArguments/)

But everytime the game launches to the default startup map instead of the new given map. The map name is right and the mission exists (can be loaded ingame) but with the parameter it won't work.

I'm using *.pak files if this matters to this topic.

Thanks in advance!

Product Version: UE 4.13
more ▼

asked Mar 16 '17 at 10:02 AM in Using UE4

avatar image

100 11 15 27

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

Try not using the full path, just give the name of the map. And always make sure the map is being cooked into the package.

more ▼

answered May 19 '17 at 02:17 AM

avatar image

4.4k 32 77 40

avatar image DisplaySweet Sep 14 '17 at 07:25 AM

Also, before this, go to File>Packaging Project>Packaging Setting, then click on Packaging on left, then,set Built Configuration to "Development" and then save and built your project.

This way you can call maps from command line as Jin_VE pointed out in the comment ... : ) ,,,

avatar image lostwoods91 Feb 22 '18 at 10:03 AM

so you can't do the trick in shipping builds at all?

avatar image Jin_VE Feb 22 '18 at 06:14 PM

Doesn't appear to be possible but there may be a way if you really need it. What we usually do is change the default loaded map so it always loads the one we want to start the game with. It's in Project Settings->Maps&Modes.

avatar image Jin_VE Feb 22 '18 at 08:19 PM

You can use your own command-line parameters. Here's my GameMode BeginPlay().

 void ADTMainGameMode::BeginPlay()
     const TCHAR* cmdLineStr = FCommandLine::Get();
     if(cmdLineStr != NULL)
         int32 inInt;
         if(FParse::Value(cmdLineStr, TEXT("RedTeam"), inInt))
             RedTeamInitialCount = inInt;
         if(FParse::Value(cmdLineStr, TEXT("BlueTeam"), inInt))
             BlueTeamInitialCount = inInt;

It looks like there are blueprint nodes that do this as well, if you need to do it there. Check the last post (currently) here.

avatar image Jin_VE Feb 22 '18 at 08:32 PM

You will probably want to get string input so my code above is just an example. If you need help with the string parsing, let me know. But that's how I get command line parameters into my game logic.

You could also add a start-up level that lets the user choose the option(s) and then loads the main level as needed.

avatar image Jin_VE Feb 22 '18 at 08:58 PM

Oh, last thing. The command line parsing is inconsistent. For UE4 command-line parameters (like -PORT or -ResX), you want to use -Option=Value but for custom non-string options, you want to use -Option Value. With strings I had to do this:

 FString inStr;
     if(FParse::Value(cmdLineStr, TEXT("IncomingIP"), inStr))
         bOverrideIncomingIP = true;
         IncomingIP = inStr.Right(inStr.Len() - 1).TrimQuotes();

And for that option I had to use the format: -IncomingIP="". It's funky but at least it works.

avatar image Jin_VE Feb 22 '18 at 09:23 PM

Sorry, last one for real. Just for the sake of completion. There are two other options.

  1. You can create a C++ class derived from UGameInstance. You want to override the StartGameInstance function, copy the code from the base class implementation, and remove the bit that gets included in shipping builds (that's what stops your command-line options). Then you need to use the custom game instance in your level.

  2. There seems to be a compile-time definition (UE_ALLOW_MAP_OVERRIDE_IN_SHIPPING). The comment reads: This can be defined in the target.cs file to allow map overrides in shipping builds.

Both options will do the same thing. Each method has its own pros and cons.

avatar image lostwoods91 Feb 22 '18 at 10:44 PM

Very useful, I'll try them all to find the best one for my situation!

Thank you!

(comments are locked)
10|2000 characters needed characters left

Yeah, I know that, but I need to create two links to use for starting the game with two different game modes. Thanks!

more ▼

answered Feb 22 '18 at 06:18 PM

avatar image

36 1 3

avatar image Jin_VE Feb 22 '18 at 08:16 PM

Please respond to comments with comments. Answers are for answers. I will respond above.

avatar image lostwoods91 Feb 22 '18 at 08:22 PM

Sorry, answering from smartphone xD

avatar image Jin_VE Feb 22 '18 at 08:25 PM

Ah. It happens. No worries. Just making sure.

(comments are locked)
10|2000 characters needed characters left

File->Package Project-> Packaging Settings and you need to find "List of maps to include in a packaged build", then add those levels that you want to run from exe. After this, just run exe with dir from this list. For e.g. "game.exe /Game/NewWorld1".

alt text

help.png (32.3 kB)
more ▼

answered May 30 '18 at 10:23 AM

avatar image

3 1 3

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question