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!
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!
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();
Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.
I am not support, I am here to learn myself.
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):
Here is my most excellent custom controller: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' }
Can anyone see what the problem is here?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 { }
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.
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.
Can you show the line it refers to?Code:Error, Unrecognized member 'Target' in class 'Controller'
Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.
I am not support, I am here to learn myself.
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;
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.
Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.
I am not support, I am here to learn myself.
It should be:
Code:FolkandsPlayerController(GameReplicationInfo.ActivePawn.Controller).Target = CurrentGroundPointer;
Unfortunately, that did not work. However this works better (irrelevant lines are deleted)...
Now it is complaining about the CurrentGroundPointer.Code:local Controller Controller; GameReplicationInfo = FolklandsGameReplicationInfo(WorldInfo.GRI); Controller = GameReplicationInfo.ActivePawn.Controller; FolklandsPawnController(Controller).Target=CurrentGroundPointer; GameReplicationInfo.ActivePawn.gotoState('Moving');
I am guessing that now the CurrentGroundPointer is not being seen as an Actor, (like Controller is/was not being seen as a FolklandsPawnController).Code:FolklandsPlayerController.uc(104) : Error, Bad or missing expression for token: CurrentGroundPointer, in '='
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!
Why didn't it work? Aside from the spelling error it's the same as what you got working.
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.
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: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;
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.
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.Code:local FolklandsPlayerController MyFPC; MyFPC = FolklandsPlayerController(GameReplicationInfo.ActivePawn.Controller);
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![]()
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:
Thanks for all your helpCode: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'); }
Bookmarks