I’d like to pass in information from the command line and then use that info to populate variables in Blueprint. Does anyone know how that could be done?
For example:
mygame.exe ?charactername=Bob
Then in blueprint, I’d like to be able to access ‘Bob’ in my character blueprint, and assign it to my character name variable. I have other variable’s I’d like populate this way as well.
Thanks for taking the time to look into that SOTO!
I better brush up on my c++ then.
So for my example should i collect the variable on start and store it in a temp variable, then use it again on my character construction to populate my variable?
#include <string>
int main (int argc, char* argv]) {
string argtest = "";
string argvalue = "";
for (int i = 0; i < argc; i++){
argtest = argv*;
if (argtest.find ("charactername=") != string::npos) {
argvalue = argtest.substr(15);
}
}
}
Then would I grab ‘argvalue’ in my character constructor and assign it to my blueprint variable ‘CharacterName’?
I’m not a programmer so if that is horrible to look at I apologize in advance! Any suggestions would be welcome!
Yes, using a switch looks to be a cleaner option. I guess I need to look at a basic code project and see how to get started with something like that.
So once you can isolate the argument your looking for, you store it in a temp variable, and then re-assign it to the variable in the blueprint somewhere in the constructor for the blueprint (in my case the character blueprint) when it is called later in the code?
I’ll check out some of the basic code project video tuts. Thanks for your help with this SOTO and ambershee. If it were possible that a “Get Console Arguments” node could be put into blueprint at some point in the future, I’m sure it would be a great addition.
So I’ve run through the code tutorial game now, so that’s a start. I’d like to modify the example to see if I can implement this idea now, how do you access the command line arguments in code? I can’t seem to find any reference info on it. Is there a function that you can call to grab a command line argument?
Bump - in case others come searching for this, there is now (4.16, possibly earlier) a blueprint node called “Get Command Line” that you can use to get the commandline string, which you can then process yourself. There are also some other options-related nodes but I’ve had mixed luck with them so just parsing the cmdline myself in BP for now.
[HR][/HR]
Note:
a. You have to use ? glyph as options separator. I don’t sure how to access options like -game from docs
b. When you call **Open Level** you can reset options with **Absolute **flag [HR][/HR]
Example:
[SPOILER]
My workaround for server/client switch from command line