• Advertisement
Sign in to follow this  

[SOLVED] Reference the controller of a pawn?

This topic is 1779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Edited by Sammieo

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement