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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Cast to PlayerController fails

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

Cast to PlayerController fails (Blueprint)

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

Cast to PlayerController with delay fails (Blueprint)

Does anyone have an idea or even a solution to my problem?

Product Version: UE 4.10
Tags:
more ▼

asked Jan 06 '16 at 01:29 PM in Blueprint Scripting

avatar image

Syrill
212 22 23 31

avatar image Matthew J Jan 06 '16 at 08:24 PM

Hello Syrill,

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.

avatar image Syrill Jan 06 '16 at 09:40 PM

Hello Matthew,

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?

GlobalDefaultGameMode=/Game/Gameplay/Lobby/BP_InitialLobbyGameMode.BP_InitialLobbyGameMode_C

Do I have to delete this line or set GlobalDefaultGameMode to None / Null?

avatar image Matthew J Jan 06 '16 at 09:55 PM

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.

avatar image Syrill Jan 07 '16 at 08:13 AM

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

avatar image FilipeTessaro Jan 07 '16 at 12:37 PM

Hi, did you try the node: "GetAllActorOfClass"? like thisalt text

I don´t know, but try something differente from "GetPlayerController" it could be the node that is preventing from casting. Or the "GetController" Node alt text

getallactors.png (244.9 kB)
getcontroller.png (278.4 kB)
avatar image Syrill Jan 07 '16 at 01:20 PM

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. CheckPlayerControllerIsValid 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: GetPlayerControllerDisplayName It prints "PlayerController" and not a specific class. However, I am not entirely sure what the display name should be...

avatar image Syrill Jan 10 '16 at 04:47 PM

Thank you both for you help!

I commented under thyshimrod´s answer what went so horribly wrong. You already had the right idea, it just took me some time to find out...

avatar image JonathanArmstrong Dec 30 '18 at 03:21 AM

@FilipeTessaro You're the man! This worked for me.

avatar image unit23 Nov 18 '16 at 06:57 PM

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.

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

1 answer: sort voted first

Hello,

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.

alt text

mapsmodes.png (55.1 kB)
more ▼

answered Jan 07 '16 at 02:00 PM

avatar image

thyshimrod
399 22 11 39

avatar image Syrill Jan 10 '16 at 04:44 PM

That, kind of, was the problem, thank you!

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.

Thanks again!

avatar image Dryfter Mar 12 '18 at 12:40 PM

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

avatar image TorQueMoD Mar 15 '18 at 07:57 AM

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?

(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