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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Unable to use PlayerArray in custom function in GameState

I'm having an issue where I cannot use PlayerArray in a static function.. I'm sure this is by design but I can't figure out a way around it. What I'm trying to do is specifically transform the player to the location of the playerstarts when the game begins. The playerstarts have their tags set

AMyGameState.h

 UCLASS()
 class CCREATURESONLINE_API ACCOCardGameState : public AGameState
 {
     GENERATED_BODY()
 public:
 
 
     static int32 getPlayerIndex(APlayerState* playerHolder);
 };

AMyGameState.cpp

 int32 ACCOCardGameState::getPlayerIndex(APlayerState* playerHolder)
 {
     int32 index = PlayerArray.Find(playerHolder);
     return index;
 }
 

AMyPlayerState.h

 UCLASS()
 class CCREATURESONLINE_API ACCOCardPlayerState : public APlayerState
 {
     GENERATED_BODY()
 
     TArray<APlayerStart*> playerStarts;
 
     APlayerStart *PlayerOne;
     APlayerStart *PlayerTwo;
     APlayerStart *Spectator;
     
     void BeginPlay();
 };


AMyPlayerState.cpp

 void ACCOCardPlayerState::BeginPlay()
 {
 
     for (TActorIterator<APlayerStart> ActorItr(GetWorld()); ActorItr; ++ActorItr)
     {
         playerStarts.Push(*ActorItr);
     };
 
     for (int32 itr; itr < 3; itr++)
     {
         if (playerStarts[itr]->ActorHasTag("Player1")) PlayerOne = playerStarts[itr];
         if (playerStarts[itr]->ActorHasTag("Player2")) PlayerTwo = playerStarts[itr];
         if (playerStarts[itr]->ActorHasTag("Spectator")) Spectator = playerStarts[itr];
     };
     
     int32 index = ACCOCardGameState::getPlayerIndex(this);
     if (index == 0)
     {
         SetActorRelativeTransform(PlayerOne->GetTransform());
         SetActorRelativeRotation(PlayerOne->GetActorRotation());
     };
     if (index == 1)
     {
         SetActorRelativeTransform(PlayerTwo->GetTransform());
         SetActorRelativeRotation(PlayerTwo->GetActorRotation());
     };
     if (index == 2)
     {
         SetActorRelativeTransform(Spectator->GetTransform());
         SetActorRelativeRotation(Spectator->GetActorRotation());
     };
 
 }
 
Product Version: UE 4.10
Tags:
more ▼

asked Jan 24 '16 at 08:01 PM in C++ Programming

avatar image

MySurvive
1 1 2 4

avatar image MySurvive Jan 24 '16 at 08:40 PM

I guess that I should add that the error I am getting is that "a nonstatic member reference must be relative to a specific object"

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

2 answers: sort voted first

int32 index = ACCOCardGameState::getPlayerIndex(this);

Your error is on this line, you can't access getPlayerIndex() like this; Instead, do something like this:

ACCOCardGameState gameState ; int32 index = gameState.getPlayerIndex(this);

more ▼

answered Jun 21 '18 at 06:12 PM

avatar image

Vrezhg
1 1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
 int32 index = ACCOCardGameState::getPlayerIndex(this);

Your error is on this line, you can't access getPlayerIndex() like this; Instead, do something like this:

 ACCOCardGameState gameState ;
 int32 index = gameState.getPlayerIndex(this);
more ▼

answered Jun 22 '18 at 12:33 AM

avatar image

Vrezhg
1 1 1

(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