I have GameCharacter c++ class, bluepring generic_NPC, inherited from GameCharacter and multiple blueprints inherited from generic_NPC: NPC1_BP, NPC2_BP etc.
What I am trying to do is to spawn exact NPC.
I already know that I need to fill reference in constructor of GameCharacter class like this:
AGameCharacter::AGameCharacter()
{
..................
static ConstructorHelpers::FObjectFinder<UBlueprint> NPCBlueprint(TEXT("Blueprint'GameFolder/../NPC1_BP.NPC1_BP'"));
if (NPCBlueprint.Object)
NPC_BP_Reference = NPCBlueprint.Object->GeneratedClass;
}
and store it in some GameCharacter class variable, I called it NPC_BP_Reference. So that I could later spawn it with something like this: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums
What I don’t understand is how can I choose exact NPC_BP to spawn?
I need somehow change TEXT("Blueprint'GameFolder/../NPC1_BP.NPC1_BP'")
, I tried to override constructor so that I could pass in TCAHR* string with reference to exact NPC to spawn, but I don’t get how do I implement it with 's snippet, or even simple ()->SpawnActor(NPC_BP_Reference, Loc, Rot, SpawnInfo);
Please advise!
UPDATE:
In the end I got it working, but not the way I’d like it to.
I had to add reference loader into GameMode class constructor and load there every NPC I wish to use in game.
What I don’t like is that every NPC loads about 4 sec (checked via VisualStudio Debugger) and that’s waaaaay to slow. For 20 NPC it would take more than a minute to just start up my game, which is not cool. So question still stands.
BTW, I tried using FObjectFinder in constructors of other classes, but editor stops loading at 71-72%.