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"

Networking: GameMode, PlayerController; connection

Recently i am trying to translate what is written in my custom Player Pawn Class to be used with a PlayerController. Because i was struggling with all the pawn-copies every single player had, i tried using Gamestate with no success.

I found out about player controllers: My goal is to get a list of all playercontrollers that are currently connected to the gamemode. So if there is a key wich is pressed by a player, the gammode can process its logic and send 1 array of player positions to each gamestate, wich then further processes the new positions to transition with what the player actually sees.

Even better would be for the playercontroller to actually have the gamemode included so i can run functions instead of checking for what has changed! my approach is something like this:

 //AServerState* Gamemode = (AServerState*)GetWorld()->GetAuthGameMode();
 //if (Gamemode)
 //    Gamemode->keyPress(...);

my solution would be to use that code sample above in my playercontroller class and maybe even: Gamemode->AddPlayerToArray((ASpherePawn*)GetPawn()); right at begin play to get a reference array of all players in game. in a 3 player example i am assuming the following: 2 players dont know about Gamemode so they simply do nothing. 3 More Playercontrollers do exist on the server and would know about inputs wich can be processed. i would have less fancy struggle by that approach, wouldnt i? what is the usual way of doing this when i need to have an update every frame?

Im just asking if im on the right way: Player Pressing Key. Instead of using clientside logic it sends the key to be processed to the single existing gamemode. the server updates his own gamestate logic. gamestate is replicated so everybody is seeing whatever was pressed simultainiously.

does the gamestate only require the DOREPLIFETIME_CONDITION or also the other functions? when the (dedicated) finishes its Tick(delta) it calls the gamestate and sends a whole player array.

thing is my game is like a simulation with physics. maybe garrysmod + 8balls is similar. and im planning on having max 16 players or maybe 2-8. so the server needs to be authoritative

this is how i connected my gamemode with its gamestate MODE.H

 AOverallState* gamestate;

MODE.CPP

 void AServerState::BeginPlay()
 {
     gamestate = GetWorld()->GetGameState<AOverallState>();
 }

wich also has an array of all pawns and should update them accordingly to what is replicated

thanks for your advice. im really not sure if gamestate.array = pawnArray would be enough to keep all clients on current state and not just the server

turned out more long than i expected. but hey its networking ;) i have some experience in this but im only 4 months into UE4 and came from NO IDE -> javascript, made my own thing with it. and also ive never posted a question ;)

Product Version: UE 4.11
Tags:
more ▼

asked Jun 15 '16 at 12:37 AM in C++ Programming

avatar image

Complex
13 2 5

avatar image Chris528 Jul 03 '16 at 10:00 PM

GameState has a TArray called PlayerArray, which contains an array of all the player states. If you want to access a player controller from a player state you can do something like

 auto currentPC = Cast<MyPlayerControllerClass>(currentPS->GetOwner());

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

1 answer: sort voted first

You should set the pawn ownership to be the player controller that is caught on post login and then send an rpc to the server and then You can replicate the key presses as you wish!

more ▼

answered Jul 04 '16 at 08:12 AM

avatar image

CyberblastSoft
253 8 12 76

(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