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"

Problems accessing class when sorting TArray

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.

Product Version: UE 4.19
Tags:
more ▼

asked Apr 02 '18 at 06:22 PM in C++ Programming

avatar image

NotSomethingElse
11 1 2

avatar image Velrin Apr 02 '18 at 06:52 PM

What is "Stats" and how is it declared?

avatar image NotSomethingElse Apr 02 '18 at 06:55 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Apr 03 '18 at 01:49 AM

avatar image

NotSomethingElse
11 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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