Results 1 to 12 of 12
  1. #1
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    43

    Default Get a Pawn's Controller

    I have a pawn with an AIController assigned (I hope).

    I want to call MoveTo on the thing: is there some sort of Pawn.getController() I can call, or should I go ahead and write one?

    Thanks!

  2. #2

    Default

    Pawn's have a variable that holds it's controller, called... Controller. :P

    If you have a custom controller, and would like to access something from it while you are in the pawn, you would use it like this MyController(Controller).MyControllerFunction();
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  3. #3
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    43

    Default

    Quote Originally Posted by Graylord View Post
    Pawn's have a variable that holds it's controller, called... Controller. :P

    If you have a custom controller, and would like to access something from it while you are in the pawn, you would use it like this MyController(Controller).MyControllerFunction();
    Excellent! Thanks!

  4. #4
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    43

    Default

    Okay, so I am trying to access my controller, but it is not recognizing my custom controller, just the default controller.

    I say this because I am getting this error:

    Error, Unrecognized member 'Target' in class 'Controller'

    This should work because my Custom AI Controller (FolklandsPawnController) includes an Actor named 'Target'.

    Here is the code I am using to attempt to set my custom controller (I left out the MouseInterface stuff, since I'm sure that's not relevent):

    Code:
    class FolklandsPawn extends UTPawn
      Implements(MouseInterfaceInteractionInterface)
      placeable;
       
    var(NPC) SkeletalMeshComponent ModelMesh;
    var(NPC) class<AIController> ModelController;
    
    simulated event PostBeginPlay()
    {
    
    //SpawnDefaultController();
    //TODO Would the following be better served by called SpawnDefaultController?
      if(ModelController != none)
      {
        //set the existing ControllerClass to our new ModelController class
        ControllerClass = ModelController;
      }
      
    
      WorldInfo.Game.Broadcast(self, "WorldInfo.PostBeginPlay");
      WorldInfo.Game.Broadcast(self, "FolklandsPawn.PostBeginPlay");
    
      Super.PostBeginPlay();
    }
    
    
    
    
    //override to do nothing
    simulated function SetCharacterClassFromInfo(class<UTFamilyInfo> Info)
    {
    }
    
    
    
    defaultproperties
    {
    
      //This is required by the MouseInterface
      SupportedEvents(4)=class'SeqEvent_MouseInput'
    
      //Setup default NPC mesh
      Begin Object Class=SkeletalMeshComponent Name=ModelMesh0
        SkeletalMesh=SkeletalMesh'CH_LIAM_Cathode.Mesh.SK_CH_LIAM_Cathode'
        PhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics'
        AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
        AnimtreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
      End Object
      ModelMesh=ModelMesh0
      Mesh=ModelMesh0
      Components.Add(ModelMesh0)
    
      //Points to your custom AIController class - as the default value
      ModelController=class'FolklandsPawnController'
    
    }
    Here is my most excellent custom controller:

    Code:
    class FolklandsPawnController extends UDKBot;
    
    var Actor Target;
    
    event Possess(Pawn inPawn, bool bVehicleTransition)
    {
        super.Possess(inPawn, bVehicleTransition);
        Pawn.SetMovementPhysics();
    }
    
    state Moving
    {
    begin:
            MoveToward(Target);
    }
    
    defaultproperties
    {
    }
    Can anyone see what the problem is here?

  5. #5
    MSgt. Shooter Person
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    338

    Default

    Don't you have to declare the controller variable first?
    Something like
    var/local FolklandsPawnController FPC;
    FPC = Controller(FolkslandController);

    then you can access FPC.Target();
    might be wrong but should work.

  6. #6

    Default

    You can, but usually you do not have to. You can access it directly.


    As for the issue, the playercontroller is set in the gametype.
    I don't think you can set it on the fly like that.

    Code:
    Error, Unrecognized member 'Target' in class 'Controller'
    Can you show the line it refers to?
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  7. #7
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    43

    Default

    Quote Originally Posted by Graylord View Post
    You can, but usually you do not have to. You can access it directly.


    As for the issue, the playercontroller is set in the gametype.
    I don't think you can set it on the fly like that.

    Code:
    Error, Unrecognized member 'Target' in class 'Controller'
    Can you show the line it refers to?
    I am doing an RTS type thing. I have an Actor CurrentGroundPointer that is the arrow that tells the currently chosen pawn where it needs to move. Each pawn will have its own target.

    Here is the actual line; it is in the FolklandsPlayerController.

    GameReplicationInfo.ActivePawn.Controller.Target=C urrentGroundPointer;

  8. #8

    Default

    That line is erronous.

    You don't just add . to go to the next layer of access. When I wrote MyPlayerController(Controller), I meant it like that, not just Pawn.Controller.
    I'm afraid I'm still shabby at accessing classes using more than one layer of access though, so I am not sure what it should be in this case.

    Something along the lines of MyPlayerController(GameInfoReplicationInfo.ActiveP awn.Controller).Target
    This is almost certainly wrong, but as you can see there's a lot more to it than simply adding a ".", it also depends on what exactly your ActivePawn Variable is.
    I'm making a game!

    http://www.desura.com/games/modulated
    Click the link above to read more!

  9. #9
    Boomshot
    Join Date
    Aug 2011
    Posts
    2,920

    Default

    It should be:

    Code:
    FolkandsPlayerController(GameReplicationInfo.ActivePawn.Controller).Target = CurrentGroundPointer;

  10. #10
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    43

    Default Getting closer...

    Quote Originally Posted by Spoof View Post
    It should be:

    Code:
    FolkandsPlayerController(GameReplicationInfo.ActivePawn.Controller).Target = CurrentGroundPointer;
    Unfortunately, that did not work. However this works better (irrelevant lines are deleted)...

    Code:
             local Controller Controller;
    
            GameReplicationInfo = FolklandsGameReplicationInfo(WorldInfo.GRI);
            Controller = GameReplicationInfo.ActivePawn.Controller;
    
             FolklandsPawnController(Controller).Target=CurrentGroundPointer;
             GameReplicationInfo.ActivePawn.gotoState('Moving');
    Now it is complaining about the CurrentGroundPointer.

    Code:
    FolklandsPlayerController.uc(104) : Error, Bad or missing expression for token: CurrentGroundPointer, in '='
    I am guessing that now the CurrentGroundPointer is not being seen as an Actor, (like Controller is/was not being seen as a FolklandsPawnController).

    There is obviously something I am not understanding about class syntax in Unrealscript; I am persistently having trouble getting my classes seen as the correct class.

    However, I am on lunch now and don't have time to look into it, I will look into it more after work.

    Thanks!

  11. #11
    Boomshot
    Join Date
    Aug 2011
    Posts
    2,920

    Default

    Why didn't it work? Aside from the spelling error it's the same as what you got working.

    Quote Originally Posted by OldLadyNevermore View Post
    There is obviously something I am not understanding about class syntax in Unrealscript; I am persistently having trouble getting my classes seen as the correct class.
    It's called scope.

    Let's say you have your FolklandsPlayerController class (and any relevant object created from it). The hierarchy the object is built from looks like this:

    FolkandsPlayerController
    PlayerController
    Controller
    Actor
    Object

    You can use a reference typed to any of those five classes to address your FolklandPlayerController object.

    Code:
    var FolklandPlayerController MyFPC;
    var Controller MyC;
    var Actor MyA;
    
    MyFPC = Spawn(class'FolklandsPlayerController'); // this is just an example, ignore the context
    MyC = MyFPC;
    MyA = MyFPC; // or even MyA = MyC;
    But, each reference is limited in scope by it's type. 'MyA' can only access the variables and functions that are known through Object and Actor. And 'MyC' is limited to anything in Object, Actor, and Controller. To understand this visually, imagine it like this:

    FolklandsPlayerController
    PlayerController
    Controller <---- MyC can 'see' everything in the object from here down
    Actor
    Object

    Remember that all of these reference point to the same object. They don't change it. It's simply the limits of their scope in being able to 'see' and access the structure of the object.

    Typecasting is required to increase scope.

    Code:
    local FolklandsPlayerController MyFPC;
    
    MyFPC = FolklandsPlayerController(GameReplicationInfo.ActivePawn.Controller);
    That takes the controller reference within the pawn referred to by ActivePawn, and casts it to a reference of type FolkandsPlayerController. If that controller object is infact a FolklandsPlayerController, then the cast succeeds. If it doesn't, MyFPC will be none.

    Assuming it succeeds, both MyFPC and GameReplicationInfo.ActivePawn.Controller will point to the same object. The former has full access to the object, while the latter cannot be used to access the custom stuff in your class, or in PlayerController.

    Hope that helps. I get a strong feeling of deja-vu whenever I try to explain this

  12. #12
    MSgt. Shooter Person
    Join Date
    Jun 2012
    Posts
    43

    Default

    Quote Originally Posted by Spoof View Post
    Why didn't it work? Aside from the spelling error it's the same as what you got working.
    You know, I can't remember what the error was; it was a lot of errors ago. However, it did strike me as odd since (as you mention) the code was essentially identical in what it was doing. Thanks for the detailed explanation, I will refer back to it again.

    Anyway, I got it working, my pawn is FINALLY following the pointer.

    In case anyone else runs into something like this, here is the code that finally worked:

    Code:
    local Controller Controller;
    
    	// Type cast to get our HUD
    	MouseInterfaceHUD = MouseInterfaceHUD(myHUD);
    
            GameReplicationInfo = FolklandsGameReplicationInfo(WorldInfo.GRI);
    
    Controller = GameReplicationInfo.ActivePawn.Controller;
    
    	HandleMouseInput((FireModeNum == 0) ? LeftMouseButton : RightMouseButton, IE_Pressed);
    	if (FireModeNum == 0) //If this was a left press
    	{
    		if (GameReplicationInfo != none)
                       {
                            FolklandsPawnController(Controller).Target = Spawn(Class'FolklandsGroundPointerActor', , , MouseInterfaceHUD.CachedMouseWorldLocation, , , true);
                            FolklandsPawnController(Controller).gotoState('Moving');
                       }
    Thanks for all your help


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.