switching pawns mid-level

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

oysterboy

New Member
Aug 4, 2005
10
0
0
I'm using the Unreal Runtime to create a single-player demo (for a design pitch, not distribution), and I need some programming help. In short, I need to toggle user control between two different characters:

-Each character has its own pawn class ('PawnA' & 'PawnB') extended from Pawn, and its own mesh & animation set. Currently, PawnA is set as the default player in the User.ini file, and PawnB was added into the level with UnrealEd.

-I've been able to change the user's mesh with an AI script build in UnrealEd, but the animation, texture, & position don't carry over, so I'd rather do this from the PlayerController side of things.

-I would also like to trigger the switch from within a cutscene, though as long as it is at least key-bindable I can manage.

-While the user is controlling one pawn, the other one doesn't need to do anything except play an idle animation until the user switches back.

Also, the simpler solution the better - my background is 3d modeling, and I have very little programming experience.

Any help would be appreciated!
 

Switch`

Pixelante
Feb 27, 2004
98
0
0
There's a console command CheatManager.Avatar() that allows you to possess another pawn of specified class name. You could tell Pawn to play idle animation in Pawn.Unpossessed() function.
 

oysterboy

New Member
Aug 4, 2005
10
0
0
Thanks for the quick reply!

I haven't been able to get Avatar to do anything - the console doesn't say 'unrecognized command', but nothing changes.

Is there something I have to do other than enter "Avatar PawnB" or "Avatar MyPackage.PawnB" into the console?
 

oysterboy

New Member
Aug 4, 2005
10
0
0
Hm...jumped the gun a bit - typing it into the console manually does exactly what I was looking for, but it isn't working from ACTION_ConsoleCommand in an AI script.
Any ideas?
 

SuperApe

Registered Monkey
Mar 20, 2004
333
0
16
Inna Jungle
wiki.beyondunreal.com
Yeah, CheatManagers (actually Object -> CheatManager) are spawned *within* a playerController object. So, a ScriptedTrigger (AIScript) cannot access the cheats.

You know this can only be done in SinglePlayer games, right? Cheats won't be available online or in multiplayer (human player) games at all.

That's why I suggested you take a look at the CheatManager code. Perhaps there are things you can do to use that code without the CheatManager.

If you just want to have it available in your SinglePlayer map, I suggest modifying the code for a Flying Mutator detailed at the bottom of the page found on my "Unreal Geek" link. It finds the player's CheatManager and calls the Fly() function on map start. Just change it to your Avatar command.
 

oysterboy

New Member
Aug 4, 2005
10
0
0
Thanks for the help, SuperApe. The sample level is single-player.

I need to be able to call the Avatar command on-the-fly from a Matinee scene - could I modify the Flying Mutator code to enable this? I basically just need something I can trigger from UnrealEd that acts as if I had typed the Avatar command into the console myself.

Sorry if this I'm making it harder than it needs to be - I'm new to programming, and the documentation so far has been pretty spotty on the relationship between the code and actors placed in the level with UnrealEd.
 

oysterboy

New Member
Aug 4, 2005
10
0
0
Okay - I've moved the bulk of the Avatar code into a fuction in my PlayerController and written a switch to keep track of which pawn class is being controlled. The function is bound to the 'tab' key for now, but as this still all happens inside the controller, I'm still unable to execute the function from an AI script.

How would I execute a keybound function within the PlayerController from an AI script?
 

SuperApe

Registered Monkey
Mar 20, 2004
333
0
16
Inna Jungle
wiki.beyondunreal.com
oysterboy said:
Okay - I've moved the bulk of the Avatar code into a fuction in my PlayerController and written a switch to keep track of which pawn class is being controlled. The function is bound to the 'tab' key for now, but as this still all happens inside the controller, I'm still unable to execute the function from an AI script.

How would I execute a keybound function within the PlayerController from an AI script?
Being new to programming, you have to tell me: you didn't modify PlayerController, did you? You should have modified a custom version of PlayerController so that you don't mess up the stock UT2k4 code.

See this.

I'm not sure if a PlayerController exhists during a matinee. I am not familiar.

That said, you could do one of a few things:

- Modify the FlyingMutator code by setting an explicit Timer setting (number of seconds) to exactly correspond to your matinee timing. Also, remove the if (<waiting to start match>) line and move the Destroy() to after the Avatar command. This way, a LevelGameInfo can hold this custom mutator and you don't need the modified PlayerController (which could be problematic, I don't know.)

- Create another custom actor (a Trigger) to call for this Avatar command. Have the trigger's Event = the (custom) PlayerController's Tag and have that trigger event run your Avatar function.

- Depending on what you're doing, you could make a custom actor for the Pawn (or whatever) you're trying to change the appearance of. If you're only changing the appearance, and do not need the code that goes with it, have this custom Actor simply reset the Display -> StaticMesh (or Mesh) property.

I am shooting in the dark because I don't know what you're trying to do and I don't know what you've done so far (in terms of programming experience).

Let us know.
 
Last edited:

oysterboy

New Member
Aug 4, 2005
10
0
0
Again, thanks for the info. Yes, I extended a custom PlayerController to add the new code.

Here is the flow of the level I'm trying to make:
-Play Intro Cutscene
-Start playing as PawnA
-Trigger Cutscene (switch control to PawnB)
-Play as PawnB
-Trigger Cutscene (switch control back to PawnA)
-Play as PawnA
-Trigger Final Cutscene

Both pawns need to be in the scene at all times, and switching out the meshes screws up the animations (they have different skeletal rigs), so I need to switch out which pawn is being controlled by the player, rather than any properties of the pawns themselves.

SuperApe said:
Create another custom actor (a Trigger) to call for this Avatar command. Have the trigger's Event = the (custom) PlayerController's Tag and have that trigger event run your Avatar function.

This sounds like the best solution, but I don't know how to do any of it :(

I've extended Trigger into SwitchPawnTrigger...do I change the event in the code or in UnrealEd? How do I know what my PlayerController tag is?

Sorry I have to keep bugging you about this - you've been really helpful so far!
 

SuperApe

Registered Monkey
Mar 20, 2004
333
0
16
Inna Jungle
wiki.beyondunreal.com
Okay.

Well, you might not be far off then. Personally, it seems that by switching Meshes, you'll be switching skeletal structures as well, even though most animation sequences are named the same. But, like I said, I'm shooting in the dark and am not sure what you are trying to do.

Because you're talking about cutscenes,
I'm going to change gears a little.

Set your PlayerController's Tag in Ued to whatever ("foo").
Now, within your PlayerController, you've got your Avatar code? Add this in there:
Code:
event Trigger (Actor Other, Pawn EventInstigator)
{
   <WhateverTheNameOfYourAvatarFunctionIs>();

   Super.Trigger(Other,EventInstigator);
}

Okay, now.
Check out Angel_Mapper's Matinee Tutorial, if you haven't already. This is the way you should already be doing the cutscenes.

Now, instead of your custom Trigger dealie, use SubAction_Trigger and match that Event name to your (custom) PlayerController's Tag. This way, you have controll over the timing of this Pawn switch.

(If you really want do this without a Matinee SubAction_Trigger (?), then you'd only need a simple Trigger in the path of your Pawn (so it will Touch the Trigger as it passes thru it), and match the Trigger Event to the PlayerController Tag.)

Good luck.
:D
 

oysterboy

New Member
Aug 4, 2005
10
0
0
PlayerControllers don't seem to be placable in Ued, so I added the tag to the default properties (Tag="ChangePawns"). However, sending out the event "ChangePawns" from a trigger in the level isn't doing anything.

Is there another way I should be setting the PlayerController ('myController')'s tag?
 

oysterboy

New Member
Aug 4, 2005
10
0
0
Also, a good reference to the kind of demo I'm making is the opening level of The Lost Vikings, when the player gets to control each of the three characters for a brief time while being introduced to their various abilities.
 

oysterboy

New Member
Aug 4, 2005
10
0
0
Nevermind - I figured it out. I just had to make the event 'myController'.

I think that's all I need for now. Thanks again for the help!