This is not the first time I cast a Player Controller, but the first time I can not get it to work. I´ve read many questions here related to [casting and Player Controllers][1], but none of them provided a solution for my problem so far.
When I click a button in my widget, I want to call a function within the Player Controller. However, the function never got called, so I searched where something goes wrong. And as it seems, I always get a valid Player Controller, but the cast somehow fails.
I tried adding a delay, as it sometimes is the solution (afaik mostly on Event Begin Play or similar), but it didn´t change anything. (Except that now I had to wait longer when testing my blueprint.)
Can you try replacing the “cast to” node with a cast to the base Player Controller class instead of the blueprint to ensure that works first? If it does, perhaps your PlayerController isn’t being set to the correct class, which would cause the cast to fail.
Do you mean the parent class of my PlayerController? Its parent class is the normal PlayerController.
I tried to cast it to two other PlayerControllers I am using and those two casts failed, too. Do you´ve any idea, why?
Oh, I think I found the problem:
Formerly, I had set the default game mode of this project to a specific blueprint, which is my base blueprint for all other PlayerControllers (except this one). I wanted to set this back to None, but the editor did not allow it.
Can I simply change this line in the DefaultEngine.ini?
Even by default there will always be a GameMode set, even if it is the default “GameMode”. You shouldn’t need to set it to none, but if you do want all of the defaults to be none, you can set those in the Project Settings. Open your project and then select (from the top left) Edit > Project Settings > Maps & Modes > Default GameMode. From here, you can select the GameMode you want. After that, select the down arrow beside Selected GameMode and you can set the individual settings for this GameMode. You can set all of these to none if you wish.
Now I did set the GameMode to None (which somehow wasn´t possible within the editor as you described, so I wrote it directly into the DefaultEngine.ini). However, the cast again does fail (also if I try to cast to other PlayerControllers)…
I don´t know, but try something differente from “GetPlayerController” it could be the node that is preventing from casting. Or the “GetController” Node
First of all: Thank you both for your help so far!
According to FilipeTessaros advise I tried to replace the “get player controller” with one of the mentioned alternatives. It did not work, though.
For “get controller” I would require a pawn, however in this blueprint I am in a widget. Thus, it causes an error.
The “get all actors from class” node works, but returns an array with length 0.
I still think the “get player controller” returns the controller I want.
This check always returns “Valid Player Controller”. According to the tooltip of the IsValid-function, this means it can not be null.
EDIT: I was curious if I could get more details about what the “get player controller” returns, so I tried this:
did you have well changed in project settings, the player controller you wish to use? In project settings/maps & modes?
You have to have a specific game mode blueprint setted in first value I rounded, to be able to modify value below, and set your player controller BP.
Each level at his own configuration, and you have to specify for each one, the player controller you want, it use. Otherwise, it will use the internal standard player controller.
Here is what happened: I try to learn from a Marketplace-project. But instead of copying everything, I try to adapt it to my concept. The cast that always failed was in the Marketplace-project, after another level was loaded. I, however, did not load this level and thought, just changing widgets would do the trick. As it turns out, the other level has a different default GameMode and, thus, the cast did not work for me.
Now, I load another level with suitable default GameMode, PlayerController and so on and everything works just fine.
Had a similar issue, and found out that it is not enough to setup the variable, you need to call it with a cast node to make it effective for validation.
Soooo I know this is an old post, but the problem still exists even in 4.18 so I’m starting here as it is exactly the same issue I’m having now…
Does that mean you deleted the aftermarket maps and everything was fine? I’m having the same issue with my project. It was fine until I added Market stuff and now I have a controller issue and your explanation is a little vague (least to me). Did you just delete maps? I tried that and I still have the issue.
None of the BP’s I’m using try to load a level anyway (although some start the example from within the Level BPs they are gone now anyway) and my default has always been my own blank Map since everything I’m doing uses widgets there is no real need for a level beyond what UE4 requires.
The only Map in my project (now) is the one I originally had but the problem still persists…is there anything else adding marketplace items changes besides the Config files? I also switched back to a previously working version (before I added the marketplace stuff) but no luck.
I have tried everything in this post (Map&Modes, Get All Actors, etc) and like I said I had no problems with the Player Controller before. In fact this is the first time I’ve had any issue with Controllers and Market projects worked in with my own and I’ve been using UE4 well over a year now.
Why is it always (little ridiculous) things like this that stop progress? Seems like something that should have been resolved a while ago…sigh
I’m also having this issue. It’s really frustrating. In my case I’m using two different player controllers, one for a menu system utilizing the Steam Party plugin on the marketplace and another for my game options and key bindings. From what I can gather from this post, I think it has to do with the fact that the player controller you’re casting to isn’t the one defined in the default game mode (or the overriding one specified in the level’s world settings) but that shouldn’t matter. Both player controllers in my case are inherited from the same Parent Class so why would the cast fail?
Just in case you are still struggling to resolve this…
I also had this issue. I think it arose because I was trying to merge in one tutorial work in to another. I finally resolved it, by following the video below. In particular the 41 second mark, where I was not using “MyPlayerController” in my GameMode BP.
hahaahahhahahahahahahahahahaahhahahahaha. this always makes me laugh, the truth is, im trying to cast to the default joystick and make it left joystick and im trying to see if i have access in this engine for that, hahahahahaahahhaaahahahahahahahahahahaha, very funny.