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 Possess Event

How do you determine when a PlayerController has possessed a Pawn? Is there an event for this?

My PlayerController creates a HUD widget on Event BeginPlay. The HUD then needs to draw information from the Pawn that is possessed by the PlayerController. The problem is that the PlayerController doesn't have a possessed Pawn at that stage. UE4 seems to set up the Pawn possession at some point after the PlayerController is created, which makes sense. I would like to "listen" in for that event so I can respond at the moment that UE4 assigns a Pawn to the PlayerController. Then I can notify the HUD of the new Pawn to start drawing information from to display. If at some point during game play the PlayerController changes Pawn, I can then also respond to that using the same event to notify the HUD of the new Pawn.

Product Version: UE 4.9
Tags:
more ▼

asked Oct 31 '15 at 12:11 AM in Blueprint Scripting

avatar image

wilberolive
318 30 45 48

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

2 answers: sort voted first

Guys, in C++, you should override AController::SetPawn method. It is the only virtual method that is guaranteed to fire as soon as the controller possesses a pawn.

more ▼

answered May 10 '17 at 10:32 AM

avatar image

codeslicer0
41 1 4 6

avatar image plato.manchi Aug 31 '17 at 03:47 PM

This is what i'm looking for

avatar image Louspirit Dec 18 '18 at 05:24 AM

Is there an equivalent in blueprint please ?

avatar image MongooseJV Feb 01 '19 at 02:52 PM

I would also like to know this as well. I'm left to do logic in the tick event until my controller is controlling a pawn =(

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

maybe there is some smarter way but in any case you can create a event dispatcher and when you override the specific functions in your gamemode you can call the event dispatcher at the right time

(ue4 spawns a default pawn specified in your gamemode and you can override those specific functions inside your gamemode)

by the way why not create the widget from your hud class specified in your gamemode ?

more ▼

answered Oct 31 '15 at 12:15 AM

avatar image

makai
434 26 17 43

avatar image wilberolive Oct 31 '15 at 12:47 AM

So your saying that I should override Spawn Default Pawn For in my custom GameMode? If I override that function, then I also need to provide the functionality for creating the pawn as well. There doesn't seem to be a parent Spawn Default Pawn For I can call to let the base GameMode create the pawn and do whatever else it needs to do, unless I'm missing it?

I'm actually not really sure where the best place is to create the HUD widget for the player. This is a multiplayer game and your comment has reminded me that the PlayerController is created for every player on the server, and I don't want the server creating a HUD widget for each player as it should just be a client-side only HUD. So perhaps the PlayerController is not the best place after all. Could you elaborate more on where I could create the HUD widget in the GameMode for each player as they join the game?

avatar image wilberolive Oct 31 '15 at 12:56 AM

Actually, a custom HUD blueprint is probably the best place to create it. Since each player has a HUD blueprint and the server doesn't create one of these for each player.

Still stuck on how to determine when the PlayerController possesses a Pawn though?

avatar image makai Oct 31 '15 at 01:05 AM

creating a pawn is quite simple, use the "Spawn actor from class" node and then use your playercontroller->Posses to posses the spawned pawn. This could be the place where you can call your Event Dispatcher. Also there is a flag "spawn as spectator" inside your gamemode which can be pretty useful if you want to have custom spawn. check out this tutorial maybe it helps: https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/RespawnPlayer/Blueprints/index.html

avatar image makai Oct 31 '15 at 12:56 AM

you can specify a hud class inside your gamemode so if you create a new blueprint and derive from "hud". everything you create there will be client side like a hud usually is.

if you want to replicate a widget for a multiplayer widget you need to create a custom event and setup your replication stuff there. if you have problems creating the hud inside the event begin, add a small delay to get sure everything has been spawned and created

gamemode

(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