Switch Client between player and spectator?
I have 2 classes one is the default Character class and one is the default Spectator class. These are both setup in a Game Mode class. I want to be able to switch between a pawn being a player or a spectator at the press of a key. When a key is hit this function is called.
This function is in my Character class and works fine on the Server side of things putting the player into a Spectator state using my custom spectator class, however on the client side it seems to break the clients controller so they are unable to move at all.
My knowledge on replication at the minute is slightly limited so I'm wondering if there is anything else I need to do in order for the client to switch between spectating and playing?
My log shows that I get the warning 'NULL GameState when trying to spawn spectator' so I'm guessing only the server has access to the GameState so how do I access it from the Client?
Still seem to be getting this problem and can't seem to find anything in the documentation to point me in the right direction.
I think the movement is handled on the server and the server never knows when you change the spectating mode on a client.
I think the most simple way to implement your desired behavior is: Annotate your SpectatorOn() method as server-side. Therefore add the following in the header:
That means that an SpectorOn method is auto-generated and that you have to implement the methods:
which are called by the auto generated method. In Validate simply return true but in the Implementation method use the Controller that is an attribute of your Character class (is defined in the base class APawn):
I highly recommend that you watch those Videos although they are related to Blueprints: (they explain a lot about Network and replication) https://www.unrealengine.com/blog/blueprint-networking-tutorials
You find the same concepts in C++ when you browse the code of the Unreal-Engine, the classes ACharacter, ADefaultPawn, APawn have a lot of examples and also checkout the Shooter-Example.
Have a nice Day!
answered Apr 28 '14 at 10:01 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here