[Question] Player index?

Some Blueprint functions ask for a Player Index input. Such as Get Player Camera.

How this PlayerIndex works? The local player is always index 0? And how to get the instigator’s index?

In my case, I’m trying to access the local player’s camera, to change its FOV (for a sniper rifle).

Also as a feedback, I remember Player Index is referenced on the blueprint door tutorial. You could explain how it works on that tutorial, and how to make the door working for multiplayer. :slight_smile:

Yes, the PlayerIndex is an index into the array of locally-connected players. It’s there to handle cases where multiple players can be playing on the same game instance, such as a splitscreen FPS or a coop ARPG. If you don’t care about those cases, then just pass in 0 and you’ll get the primary (only) player.

If you do care about those cases though, I’d suggest avoiding those functions altogether for anything other than prototyping. There are usually other ways to get the data for the appropriate player. For example in your case, the sniper rifle should be able to find the Pawn that is wielding it, which knows which Controller is controlling it, which in turn knows which PlayerCamera you should be modifying (if it’s a PlayerController, naturally).

Also, re the door tutorial, I’ll pass your feedback onto the docs team. :slight_smile:

Cheers!
Jeff

The weapon will know which pawn is wielding it, and the controller, however the camera is client side only.

It’s better to grab the local player index, as I’d assume it would only be the local player changing the FOV for the sniper rifle :wink:

Clear now, thanks you both!

The local player index is always zero (most of the time when doing multiplayer, you only need to determine if the event is happening on the authority or not, you do not need to use player index).

The instigator will have a unique index on the server that you can use if you need to. Be aware that this will not be the same index as on that instigator’s client (they will be local and therefore zero :wink: )