Skip to main content
GameDev.net gamedev.net
🔒 Locked

[SOLVED] Reference the controller of a pawn?

Started by Sammieo Mar 10, 2013 at 4:56 PM 1 replies 1.9k views
Original Post
Sammieo
Sammieo

Hey guys,


I've got a player character and NPC in UDK, each with their own pawns and controllers. I want to, within the NPC's controller, trigger a function in the player's controller, but I only have the player's pawn as a reference.

I've tried googling and looking through documentation for an answer, but have been unlucky. I also tried something like this:


MyPawn.Controller.DoFunction();


Since I know we can refer to the Pawn from a controller or an actor, but I got an error:


MyPawn.Controller.BeStunned();


Triggers the error: "Unrecognised member 'BeStunned' in class 'Controller'. This happens even though I have a BeStunned function inside MyController.

Any help for a newbie short on luck would be most appreciated!

ratrace135
ratrace135

The Controller variable is a valid reference to your pawn's controller, but it's of the class Controller. When you have MyPawn.Controller.BeStunned(), you're calling the function from the Controller class, which is where the error's coming from. You'll need to cast the Controller variable to get it working. Something like this should do the trick:


MyController( MyPawn.Controller ).BeStunned();

It's also a good idea to check if the cast actually worked, but if the pawn's controller will always be MyController, it's not necessary (though still recommended). If you're going to be calling MyController functions a lot, it might be better to use a local variable instead of casting a bunch of times, like:


function Whatever()
{
   local MyController PC;

   PC = MyController( MyPawn.Controller );

   if( PC != None )
   {
    //Do function calls
   }
}
Sammieo
Sammieo

That seems to work just fine, ratrace. Thanks for the advice!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.