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"

TMap in UStruct causing issue

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 :p . . 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 :)

Product Version: UE 4.16
Tags:
more ▼

asked Feb 12 '18 at 03:19 AM in C++ Programming

avatar image

YourBabaYaga
3 1 2 6

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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