When i stop play from the editor, the editor will crash if AbilityStartSet is not empty. The code is used on beginplay and works fine while playing, but crashes the editor when the game stops.
In LevelSetup.h
UFUNCTION(BlueprintCallable, Category = LevelSetup)
TArray<UPlayerAbility*> GetStartSet();
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = LevelSetup)
TArray<TSubclassOf<UPlayerAbility>> AbilityStartSet;
And in LevelSetup.cpp
TArray<UPlayerAbility*> ALevelSetup::GetStartSet(){
TArray<UPlayerAbility*> temp;
for (int32 i = 0; i < AbilityStartSet.Num(); i++)
{
UPlayerAbility *Ability = AbilityStartSet.Pop()->GetDefaultObject<UPlayerAbility>();
temp.Add(Ability);
}
return temp;
}
I use this code to be able to select some UPlayerAbility’s directly from the editor and then instantiate them with the GetStartSetMethod (which is called from a blueprint).