Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: Get a Pawn's Controller

  1. #11
    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:


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

    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:

    Controller <---- MyC can 'see' everything in the object from here down

    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.

    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

  2. #12
    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:

    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);
    Thanks for all your help

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts