Player controller issue

hello, I’m making my first game and I have some issues, I saw that the “player index” was not working in multiplayer, no luck my game is multiplayer … I need to get the player controller to cast it to my BasePlayerController and then get the team of the player (see screenshot) is there an alternative to “player index” ? thanks a lot :smiley:

Try this one

GetController

The target should be a reference to self.

it gets a Controller, not a PlayerController. it cannot go through my cast :confused:

Make sure your game mode class is using your player controller class and not the default one

yeah all the controller and Gamemode is working, it is only this code that is not working, i need an alternative to get the playercontroller

This is the alternative. Look, it works. I tested it.

GetController is the way to go. Can you show a screenshot of your gamemode class please?

Edit: FYI it is perfectly possible to cast from Controller to a PlayerController or any of its children, since Controller is a Parent class to them.

it doesn’t work :frowning:
here is a screen of my character class now :

proof of not working :

it is a c++ class the controller

Can you show me a screen shot of your gamemode class please?

and also a screenshot of your world settings

and

BaseGameMode.cpp

BaseGameMode.h

Ok there’s only one reason the cast can fail and that is if it is getting a different controller class instead of your custom player controller class. Please try this and tell me the output.

I tried it and I got my custom player controller class. Maybe you’ll get something different.

it doesn’t output anything, weird …

So… there is no controller then?.. I mean, it is probably a null reference

there is no controller, but there is a player controller, i think it is different from what i’ve seen on the forums…
if i was not having any player controller, the get player controller (the one that took an index) would be null and it would not be working …

Well just remember that controllers only exist locally on clients that own them. Maybe you are testing this on a server window that has no controller or doesn’t even spawn a player? Or maybe you are making the controller possess the player after a certain amount of time so on begin play there is no controller yet? I’m not sure what the reason for not printing is but what I’m sure of is that if the controller is not null at that point, then something should be printed

Edit: Controller or PlayerController. I don’t think the class makes a difference since they are in the same hierarchy

Edit 2: Wait, were did you put that code? The one for printing the controller class name. In what blueprint class. The GetController node should only be used on pawn classes and their children

it is used in the Character class, Soldier
nope i am not on server mode
i didn’t make a timer to possess the character in my c++ code
i could be having an idea, the GetController maybe only works for the Pawn and not for the Character …

i could be having an idea, the GetController maybe only works for the Pawn and not for the Character …

Comon pal, that is not the problem. I showed you it works with my first 2 screen shots, I’m it using inside the ThirdPersonCharacter blueprint which inherits from Character which inherits from Pawn. So no, that is not the problem. You created your custom GameMode class with C++ so you are probably handling controller creation when players log in and other stuff in there so my guess is that the problem is there somewhere. You know your system better than anyone. Know that there is no other built in way to get the controller of a controlled character/pawn other than GetController providing the reference to the instance of the pawn class or anything that ends up inheriting from pawn.

okay, thanks i guess, i mean i’m in blueprint too much, and i though i would get into it, but it seems hard and inefficient. Thanks for everything mate ^^

EDIT : you know that Character class and Pawn class are different right ?

EDIT : you know that Character class and Pawn class are different right ?

Lol, I almost felt offended by that question.

You know Character inherits from Pawn right?

110434-acharacter.png

i know but what you showed me could have been a pawn blueprint, not an Character blueprint, sorry i made you feel offended x) it could be a reason, or a bug but idk

You have not been checking my posts carerfully I guess.

This is what I said:

I’m it using inside the ThirdPersonCharacter blueprint which inherits from Character which inherits from Pawn

Besides, the first screenshot shows you that it “wasn’t” a Pawn blueprint, on the top part of the image it says the class I was using.

ThirdPersonCharacter > EventGraph

And once again

could have been a pawn blueprint, not an Character blueprint

That is less than irrelevant unless you are using classes that inherit only from pawn, side by side, with classes that inherit from Character.

For some reason you give me the impression that you are fixated on thinking that the problem isn’t something related to your code.

Good luck