Announcement

Collapse
No announcement yet.

TArray pointer issues

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    TArray pointer issues

    I'm absolutely new to UE4 and C++. My background is Perl but I was talked into helping with some game programming.
    This is the pertinent section of code in the cpp file.

    in the *.cpp file
    Code:
        static ConstructorHelpers::FObjectFinder<UDataTable> StarNameTableObject(TEXT("DataTable'/Game/Data/Core/DataTables/starnames.StarNames'"));
        if (StarNameTableObject.Succeeded()) {
            StarNameTable = StarNameTableObject.Object;
            if (StarNameTable != nullptr)
            {
                TArray<FStarNames*> GetList;
    
                StarNameTable->GetAllRows<FStarNames>(TEXT("Starname retrieval failed"), GetList);
                int Count = GetList.Num();
                UE_LOG(LogTemp, Warning, TEXT("My Star Names Imported %d"), Count);
     FString MyName = GetList[0];
    UE_LOG(LogTemp, Warning, TEXT("My First Name Imported %s"), MyName);
            }
            else { UE_LOG(LogTemp, Warning, TEXT("Star Names NOT Imported")); }
        }
    The red section is what I'm currently having issues with and I know it has to do with using a point in defining the TArray (FStarNames*). The VS compiler says:
    'Error C2440 'initializing': cannot convert from 'FStarNames *' to 'FString'

    In the *.h file the TArray is declared like this:
    Code:
    UCLASS()
    class MYCLASS_API AGalaxySpawner : public AActor
    {
        GENERATED_BODY()
    
    public:    
        // Sets default values for this actor's properties
        AGalaxySpawner();
    
    protected:
        // Called when the game starts or when spawned
        virtual void BeginPlay() override;
    
    public:    
        // Called every frame
        virtual void Tick(float DeltaTime) override;
    
       UPROPERTY(EditAnywhere)
            UDataTable* StarNameTable;
    
        TArray<FStarNames*> MyStarName;
    };
    Now, when I comment out the red marked code, it compiles and runs. So I'm obviously missing something about using pointers especially in this context.


    #2
    This doesn't have to do with Pointers, but more with just data types.

    You have an array of FStarNames pointers (so, an array of things pointing to FStarNames), but you are trying to implicitly cast that to an FString.

    Code:
    FString MyName = GetList[0]; // Invalid, trying to cast from FStarName* to FString
    FStarName* MyName = GetList[0]; // Valid, you're grabbing the first FStarName* in the list.
    
    // Then you would access that FStarName however. Either through the -> operator, or the deference operator ( * ) I'm not sure what an "FStarName" is, so I can really tell you which to use.
    Able Ability System - A high performance, robust ability system for UE4. Now Available!

    Comment

    Working...
    X