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.
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 … : ) ,
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.
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.
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:
Sorry, last one for real. Just for the sake of completion. There are two other options.
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.
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.
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”.
I was trying to allow user-defined command-line arguments to be parsed by my game in shipping builds, that runs much faster, and didn’t know how to use the UE_ALLOW_MAP_OVERRIDE_IN_SHIPPING compile-time definition in .Target.cs file to allow it, as @anonymous_user_49a519741 suggested.
It seems to work on my side after adding it like this to .Target.cs file:
using UnrealBuildTool;
using System.Collections.Generic;
public class TransportGridTarget : TargetRules
{
public TransportGridTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
ExtraModuleNames.AddRange( new string[] { "TransportGrid" } );
ProjectDefinitions.Add( "UE_ALLOW_MAP_OVERRIDE_IN_SHIPPING=1" );
}
}