x

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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Can we make command line arguments?

Hello there, I would like to add a new command line argument to my game that enables a special mode, is there any way that I can create a new one without needing to modify the engine?

Greetings.

Product Version: Not Selected
Tags:
more ▼

asked Oct 26 '14 at 04:23 PM in C++ Programming

avatar image

EIREXE
43 10 15 20

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

8 answers: sort voted first

Since there was no answer chosen and a few comments, here is an example of what I used to do this. To do strings, I have to do -param="STRING", so I need the quotes and the equals sign. Here is a sample command and tthe code that pareses it.

EDIT: I noticed I forgot to strip the = sign.

mygame.exe -skinByClass -startPose 2 -scb="\pathtoafile"

 FString fileName;
 uint32 startPose;
 
 //string
 if (FParse::Value(FCommandLine::Get(), TEXT("scb"), fileName)) {
     fileName = fileName.Replace(TEXT("="), TEXT("")).Replace(TEXT("\""), TEXT("")); // replace quotes
     _SCBFile = fileName;
 }
 
 //integer
 if (FParse::Value(FCommandLine::Get(), TEXT("startPose"), startPose)) {
     _startPose = startPose;
 }
 
 //boolean
 if (FParse::Param(FCommandLine::Get(), TEXT("skinByClass"))) {
     _skinByClass = true;
 }
 



more ▼

answered Jul 23 '15 at 07:05 PM

avatar image

fishhead2567
106 2 72 13

avatar image Vaei Jan 06 '18 at 12:46 AM

For future googlers like myself

This is the correct answer

avatar image Keijiroh May 29 '18 at 12:47 AM

Do you know how can I get string parameter including ","? FParse::Value(FCommandLine::Get(), TEXT("scb"), fileName) get just before ",".

avatar image M.SHAHEER.M Sep 17 '18 at 12:02 PM

where shall i add this code? i need to add a boolean check for the user which will run a specific code block in the client_example.py

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Yes

try running this anywhere

 if(FParse::Param(FCommandLine::Get(), TEXT("MyFlagPresent")))
 {
   //UE_LOG or Printstirng "My flag was present in the commandline!" ;
 }


and run the game with

-MyFlagPresent

Rama

more ▼

answered Oct 26 '14 at 04:57 PM

avatar image

Rama
10.6k 446 343 1086

avatar image EIREXE Oct 26 '14 at 06:39 PM

Just what I needed, thanks!

But what about getting parameters after flags?

like -MyFlagPresent 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

My Solution

 The .h file....
 
     UFUNCTION(BlueprintCallable, Category = TDLHelpers)
         static bool CommandLineArgPresent(FString key = "unknown");
     UFUNCTION(BlueprintCallable, Category = TDLHelpers)
         static FString CommandLineArgValue(FString key = "unknown", FString defaultValueIfAbsent = "empty");
     UFUNCTION(BlueprintCallable, Category = TDLHelpers)
         static int32 CommandLineArgIntValue(FString key = "unknown", int32 defaultValueIfAbsent = 0);
 
 
 and in the .cpp file...
 
 bool UtdlBlueprintHelpers::CommandLineArgPresent(FString key)
 {
     return FParse::Param(FCommandLine::Get(), *key);
 }
 
 FString UtdlBlueprintHelpers::CommandLineArgValue(FString key, FString defaultValueIfAbsent)
 {
     FString s;
 
     if (FParse::Value(FCommandLine::Get(), *key, s)) {
         return s;
     }
 
     return defaultValueIfAbsent;
 }
 
 int32 UtdlBlueprintHelpers::CommandLineArgIntValue(FString key, int32 defaultValueIfAbsent)
 {
     int32 i;
 
     if (FParse::Value(FCommandLine::Get(), *key, i)) {
         return i;
     }
 
     return defaultValueIfAbsent;
 }
more ▼

answered Aug 14 '15 at 04:29 AM

avatar image

SND R Keene
963 31 118 112

avatar image Weibye Jan 03 '19 at 10:58 AM

If using command line parameters like this:

 -ParamBool -ParamInt 3 -ParamValue="MyTextValue"


then a quick removal of the = sign is necessary.

  FString UtdlBlueprintHelpers::CommandLineArgValue(FString key, FString defaultValueIfAbsent)
  {
      FString s;
  
      if (FParse::Value(FCommandLine::Get(), *key, s)) {
          return s.Replace(TEXT("="), TEXT(""));
      }
  
      return defaultValueIfAbsent;
  }
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hi, you've probably already found the answer to this, but in case anyone else is looking, having a look at Parse.h gives the clue: you can use the "Value" method of FParse, eg:

  int32 val;
   if(FParse.Value(FCommandLine::Get(), TEXT("MyFlagPresent"),val)) {

       blah
   }

Also, you can manually parse the string returned by FCommandLine::Get().

more ▼

answered Mar 20 '15 at 08:26 AM

avatar image

RichardB
134 2 4 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

We have a small plugin to access command line parameters from Blueprint: https://github.com/DescendentStudios/CommandLineParametersPlugin

more ▼

answered Jul 18 '17 at 08:52 PM

avatar image

Stormwind
56 1 4 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
 Just what I needed, thanks!
 
 But what about getting parameters after flags?
 
 like -MyFlagPresent 1

I would love to know this answer as well.

more ▼

answered Nov 14 '14 at 06:20 PM

avatar image

blurdot
53 5 6 26

avatar image Omberone Jun 18 '15 at 04:45 PM

Same here. Works for me when using standard exe, but not on my server.exe.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

hello,i am a new programer ,i don't know how to use Command-Line Arguments,can you tell me? thank you very much!!

more ▼

answered Mar 05 '17 at 12:01 PM

avatar image

王振十年
1 1 1

avatar image krisgoku2 May 27 '17 at 09:48 PM

This is actually really strange. The way they present command lines but in game..Their should be a library

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

You can also just put the "=" into the parser function so you don't need to modify the string later on.

 FString GameModeArg;
 if (FParse::Value(FCommandLine::Get(), TEXT("-gamemode="), GameModeArg))
 {
 GameMode = GameModeArg;
 }
         
more ▼

answered May 23 '19 at 02:10 PM

avatar image

MadSystem
1 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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