Followers 0

# [SOLVED] Reference the controller of a pawn?

## 2 posts in this topic

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
0

##### Share on other sites

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

0

##### Share on other sites

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

0

## Create an account

Register a new account