Array to sort:
TArray<ASCharacter*> TurnOrderArray;
Sorting in a custom game mode:
TurnOrderArray.StableSort([](ASCharacter ArbitraryChar, ASCharacter ArbitraryChar2)
{
return ArbitraryChar.AttInventory.Stats.FindRef("Reflexes") < ArbitraryChar2.AttInventory.Stats.FindRef("Reflexes");
});
Struct declaration in ASCharacter:
public:
UPROPERTY(BlueprintReadWrite, Category = "CharacterAttributes")
FCharacterAttributes AttInventory;
error says:
Error C2248 ‘ASCharacter::ASCharacter’: cannot access private member declared in class ‘ASCharacter’
I replaced the binary predicate within the StableSort with a simple function in the ASCharacter class and had the same access problem.
Velrin
(Velrin)
2
What is “Stats” and how is it declared?
In a custom game instance
USTRUCT(BlueprintType)
struct FCharacterAttributes
{
GENERATED_USTRUCT_BODY()
UPROPERTY(BlueprintReadWrite, Category = "CharacterAttributes")
TMap<FString, int32> Inventory;
UPROPERTY(BlueprintReadWrite, Category = "CharacterAttributes")
TMap<FString, float> Stats; //HERE
UPROPERTY(BlueprintReadWrite, Category = "CharacterAttributes")
float Health;
UPROPERTY(BlueprintReadWrite, Category = "CharacterAttributes")
EClass Class;
UPROPERTY(BlueprintReadWrite, Category = "CharacterAttributes")
FString Name;
UPROPERTY(BlueprintReadWrite, Category = "CharacterAttributes")
TArray<FString> StatusEffects;
UPROPERTY(BlueprintReadWrite, Category = "CharacterAttributes")
bool IsAPlayerCharacter;
UPROPERTY(BlueprintReadWrite, Category = "CharacterAttributes")
int32 PartyNumber;
UPROPERTY(BlueprintReadWrite, Category = "CharacterAttributes")
int32 PartyPosition;
};
I’m going to assume most of what I’m doing is bad practice because I’m a complete noob.
For anyone who encounters a similar problem: I changed this -
TurnOrderArray.StableSort([](ASCharacter ArbitraryChar, ASCharacter ArbitraryChar2)
{
return ArbitraryChar.AttInventory.Stats.FindRef("Reflexes") < ArbitraryChar2.AttInventory.Stats.FindRef("Reflexes");
});
to
TurnOrderArray.StableSort([&](ASCharacter& ArbitraryChar, ASCharacter& ArbitraryChar2)
{
return ArbitraryChar.AttInventory.Stats.FindRef("Reflexes") < ArbitraryChar2.AttInventory.Stats.FindRef("Reflexes");
});
And it compiled and seems to work fine now.