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"

How to access an array element from a pointer?

I'm having problems with this code


     virtual void BeginPlay() override;
     // Arrays of all of the spawn points that are available
     TArray<ASSpawnPoint*> TeamOneSpawnPads, TeamTwoSpawnPads;
     // Integers that hold the number of players on each team
     int32 TeamOneAmount, TeamTwoAmount;


 FVector ASGameMode::GetSpawnLocation(int32 Team)
     FVector NewSpawnLocation = FVector(0.0f);
     TArray<ASSpawnPoint*>* SpawnPads;
     // Set up an array that points to the correct teams spawn point array
     if (Team == 1)
         SpawnPads = &TeamOneSpawnPads;
         SpawnPads = &TeamTwoSpawnPads;
     // Generate a random number that we will use to reference a spawn pad
     int32 RandomSpawnerInt = FMath::FRandRange(0.0f, SpawnPads->Num() - 1);

     // Get a reference to the spawn pad we will be using
     // I'm pretty sure this is what is causing problems
     ASSpawnPoint* SpawnPad = SpawnPads[RandomSpawnerInt];
     // Set the location that we will return to the location we get from the spawn pad
     NewSpawnLocation = SpawnPad->GetRespawnLocation();
     // Remove the spawn pad from the availability array
     return NewSpawnLocation;


 (21): `error C2440: 'initializing': cannot convert from 'TArray<ASSpawnPoint *,FDefaultAllocator>' to 'ASSpawnPoint *&'

Product Version: UE 4.20
more ▼

asked Jan 18 '19 at 08:47 PM in C++ Programming

avatar image

35 6 13 13

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

1 answer: sort voted first

You need to deference the array pointer to use the [] operator.

 ASSpawnPoint* SpawnPad = SpawnPads[RandomSpawnerInt];


 ASSpawnPoint* SpawnPad = (*SpawnPads)[RandomSpawnerInt];
more ▼

answered Jan 18 '19 at 10:11 PM

avatar image

2.2k 39 17 52

avatar image Void_Gabe Jan 18 '19 at 10:26 PM

Thank you! I've been trying to figure this out for days.

(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