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"

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 :D

Image

Product Version: UE 4.10
Tags:
more ▼

asked Oct 11 '16 at 01:18 PM in Blueprint Scripting

avatar image

Brieyla1
33 1 7 7

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

1 answer: sort voted first

Try this one

GetController

The target should be a reference to self.

more ▼

answered Oct 11 '16 at 04:09 PM

avatar image

MacDx
600 17 9 33

avatar image Brieyla1 Oct 11 '16 at 04:27 PM

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

avatar image MacDx Oct 11 '16 at 04:34 PM

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

avatar image Brieyla1 Oct 11 '16 at 04:39 PM

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

avatar image MacDx Oct 11 '16 at 04:47 PM

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

alt text

alt text

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.

test.png (92.4 kB)
test1.png (294.6 kB)
avatar image Brieyla1 Oct 11 '16 at 04:56 PM

it doesn't work :( here is a screen of my character class now : alt text

proof of not working : alt text

it is a c++ class the controller

avatar image MacDx Oct 11 '16 at 05:01 PM

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

and also a screenshot of your world settings

avatar image Brieyla1 Oct 11 '16 at 05:38 PM

alt text

and

BaseGameMode.cpp http://pastebin.com/9HWcYzfB

BaseGameMode.h http://pastebin.com/xptcVdHy

avatar image MacDx Oct 11 '16 at 05:59 PM

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.

alt text alt text

test2.png (45.8 kB)
test3.png (196.8 kB)
avatar image Brieyla1 Oct 11 '16 at 06:08 PM

it doesn't output anything, weird ... alt text

avatar image MacDx Oct 11 '16 at 06:11 PM

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

avatar image Brieyla1 Oct 11 '16 at 06:17 PM

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 ...

avatar image MacDx Oct 11 '16 at 06:31 PM

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

avatar image Brieyla1 Oct 11 '16 at 07:10 PM

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 ...

avatar image MacDx Oct 11 '16 at 07:19 PM

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.

avatar image Brieyla1 Oct 11 '16 at 07:22 PM

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 ?

avatar image MacDx Oct 11 '16 at 07:26 PM

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?

alt text

acharacter.png (12.2 kB)
avatar image Brieyla1 Oct 11 '16 at 07:30 PM

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

avatar image MacDx Oct 11 '16 at 07:41 PM

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

avatar image Brieyla1 Oct 12 '16 at 10:42 AM

yeah it was related to my code, but not too much, let me explain; the blueprint code stats a fraction of a second before the code, and goes faster, so i'm not putting any delay in my c++ code but the blueprint does. so if i put a small delay in the blueprint (see image) the controller and player state are now assigned !! hope this helps someone :D alt text

(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