Hello . . I am a bit noob in ue4 c++ and i was wondering if anyone could help me with a simple problem i am having . . i have a C++ class named BanditCharacter(Which inherits from character class) , i have also created a blueprint based on it which i want to spawn at runtime . . i am doing that in a LevelManager class . . the spawning part is working , however this BanditCharacter class has a function CustomInit() which intializes 3 properties of Bandit (SkeletalMesh, AnimInstanceClass and Material). All these properties that i want to set are in a USTRUCT in level manger class i have also created a blueprint of level manager and exposed my struct to it so that i can add things to the struct in editor , which i did . . now in my c++ LevelManager class when i call the function CustomInit() on the Bandit after spawning it and i fed this function data from the struct , the engine crashes when the spawn logic fires. . below is the structure and logic of spawning
USTRUCT(BlueprintType)
struct FBanditInformation
{
GENERATED_BODY();
UPROPERTY(EditAnywhere, BLueprintReadWrite, Category = "Structures", meta = (AllowPrivateAccess = "true"))
TMap<FName, class USkeletalMesh*> NamesWithMesh;
UPROPERTY(EditAnywhere, BLueprintReadWrite, Category = "Structures", meta = (AllowPrivateAccess = "true"))
TMap<class USkeletalMesh*, TSubclassOf<class UAnimInstance>> MeshWithABPs;
UPROPERTY(EditAnywhere, BLueprintReadWrite, Category = "Structures", meta = (AllowPrivateAccess = "true"))
TMap<FName, class UMaterial*> NamesWithMaterials;
FBanditInformation()
{
NamesWithMesh.Empty();
MeshWithABPs.Empty();
NamesWithMaterials.Empty();
}
};
this is the spawning logic:
SpawnedBanditRef = World->SpawnActor<ABanditCharacter>(CurrentBPBandit, Location, ROtation, BanditSpawnParams);
if (SpawnedBanditRef)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Purple, TEXT("Bandit Spawned!!"));
}
UJungle_BanditsSaveGame* LoadFromSaveInst = Cast<UJungle_BanditsSaveGame>(UGameplayStatics::CreateSaveGameObject(UJungle_BanditsSaveGame::StaticClass()));
LoadFromSaveInst = Cast<UJungle_BanditsSaveGame>(UGameplayStatics::LoadGameFromSlot(LoadFromSaveInst->SaveSlotName, LoadFromSaveInst->UserIndex));
USkeletalMesh* MeshToSet = *(BanditInfoStruct.NamesWithMesh.Find(LoadFromSaveInst->CurrentBanditFamily));
TSubclassOf<UAnimInstance> ABPToSet = *(BanditInfoStruct.MeshWithABPs.Find(MeshToSet));
UMaterial* MaterialToSet = *(BanditInfoStruct.NamesWithMaterials.Find(LoadFromSaveInst->CurrentBanditFamily));
SpawnedBanditRef->CustomInit(MeshToSet, ABPToSet, MaterialToSet);
}
These TMap’s are causing issues i don’t know why . I have FName saved in my savegame which i m fetching to Find funciton of TMap and if you are wondering why use TMaps then i would say because they are easy and exciting . .
This Spawning functionality with TMaps work just fine if i do all of this in just blueprints but i want to make it work in c++ as well . . Any help would be appreciated . .thnx