Mutator is reading values from an ini, that need to be set as default values for a pawn class, that
is also being read from the ini. These values must be set BEFORE the pawn is spawned.
An example would be the bHasBaby default for the UnrealShare.Cow class.
Of course the mutator has to preserve the original default value for the class, to maintain
compatibility with everything else. (And itself.... )
Note, this mutator also sets values after the pawn has spawned. No problems with those.
The mutator reads in the Name, Value to be set, and a boolean that tells it if the value
needs to be applied before or after the pawn has spawned.
This question is ONLY about the settings that need applied to the class BEFORE the pawn is actually
spawned by the mutator. (Just to be clear. I hope.....)
I have banged together a solution that seems to work with the things I have tested it with, but it is just ugly I think....
This bit of code is out of the function that spawns the pawns.
The string values for the SetCnt array and the SetName/DefName arrays used in the ConsoleCommand() calls have been
created & preloaded with the values in the PostBeginPlay() function.
i.e. SetName0[0] = "Set UnrealShare.Cow bHasBaby True" & DefName0[0] = "Set UnrealShare.Cow bHasBaby False"
Here is the code in question:
Code: Select all
for (i = 0; i<SetCnt[SwarmNum]; i++)
{
switch(SwarmNum) {
case 3: if ((SetName3[i] != "") && (SwarmSettings3[j].bPreSpawn)) { log(SetName3[i]); ConsoleCommand(SetName3[i]); } break;
case 2: if ((SetName2[i] != "") && (SwarmSettings2[j].bPreSpawn)) { log(SetName2[i]); ConsoleCommand(SetName2[i]); } break;
case 1: if ((SetName1[i] != "") && (SwarmSettings1[j].bPreSpawn)) { log(SetName1[i]); ConsoleCommand(SetName1[i]); } break;
case 0: if ((SetName0[i] != "") && (SwarmSettings0[j].bPreSpawn)) { log(SetName0[i]); ConsoleCommand(SetName0[i]); } break;
}
}
NewPawn = Spawn(aC,,,Location);
if ( NewPawn == None )
{
return false;
}
for (i = 0; i<SetCnt[SwarmNum]; i++)
{
switch(SwarmNum) {
case 3: if ((DefName3[i] != "") && (SwarmSettings3[j].bPreSpawn)) { log(DefName3[i]); ConsoleCommand(DefName3[i]); } break;
case 2: if ((DefName2[i] != "") && (SwarmSettings2[j].bPreSpawn)) { log(DefName2[i]); ConsoleCommand(DefName2[i]); } break;
case 1: if ((DefName1[i] != "") && (SwarmSettings1[j].bPreSpawn)) { log(DefName1[i]); ConsoleCommand(DefName1[i]); } break;
case 0: if ((DefName0[i] != "") && (SwarmSettings0[j].bPreSpawn)) { log(DefName0[i]); ConsoleCommand(DefName0[i]); } break;
}
}
Shirley there must be a better way?
*Bonus point to any reply's that have the correct admonishment as the last line.