Jump to content

  • Log In with Google      Sign In   
  • Create Account


[SOLVED] Reference the controller of a pawn?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Sammieo   Members   -  Reputation: 147

Like
0Likes
Like

Posted 10 March 2013 - 10:56 AM

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, 10 March 2013 - 04:06 PM.


Sponsor:

#2 ratrace135   Members   -  Reputation: 445

Like
0Likes
Like

Posted 10 March 2013 - 02:20 PM

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


#3 Sammieo   Members   -  Reputation: 147

Like
0Likes
Like

Posted 10 March 2013 - 04:01 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS