Adding Values to TMap on Constructor fires an exception (Edito debug Mode Visual studio)

Hello everyone,

I was just trying to add values to a TMap on Constructor in order to give some default values and for some reason it fires an exception,

My Tmap is quite a standar UPROPERTY;

 UPROPERTY(BlueprintReadOnly, EditAnywhere)
        TMap<EJinCondition,float> SprintDataMultiplayer;

And the Constructos is just a straightfoward add methods:


    //Populate the map with the proper values
    SprintDataMultiplayer.Add(EJinCondition::Normal, 1.f); //Triggers Exception
    SprintDataMultiplayer.Add(EJinCondition::Tired, 1.2f); //Triggers  Exception
    SprintDataMultiplayer.Add(EJinCondition::Exhausted, 1.5f); //Triggers Exception
    SprintDataMultiplayer.Add(EJinCondition::Collapse, 2.f); //Triggers Exception


The thing is i can see the values being populated on editor despite of the exception. Unlucky for me there is no description of that exception on visual studio debugger.

If anyone knows somwthing about this issue would like to know how what I’m doing wrong.

Thanks in advance

Note: I’m using version 4.22.3

You don’t generally want to initialize things in the Constructor in UObjects. Try moving things over to OnBeginPlay and see if that fixes things. Otherwise, post the wording of the exception.

But moving OnBeginPlay willl override the designer’s values. My intention is just to provide a default values for a TMap, and designer being able to modify them at their will.

You can just add some simple checks. OnBeginPlay would happen after OnLoad (where designer values are set), so that should work.

if (MyMap.Count() == 0)
   // Toss in some default values.

Thanks, that worked fine :smiley: