Download

Can a character have 2 controllers without using a dummy pawn?

I have a character that needs to have an AI controller for movement. Something like an RTS game. It also needs a player controller. So what I am doing now is creating a dummy pawn and attaching it to the character and the playercontroller posses dummy pawn which is attached the playercharacter.

How ever is there a better way to do something like this? Without using the extra pawn?

I have the same setup, and I agree it’s ugly. I did read something that Mieszko wrote a while back that suggested perhaps the intermediate pawn isn’t necessary - that maybe your player controller doesn’t need to possess any pawn, and just relays the commands directly to the AI controller.
I haven’t tried it yet. I was kind of hoping there might be a proper addition to the engine to handle doing this kind of thing more cleanly.

I am trying to do the same thing.

I am currently trying to just create a pawn with a PawnMovementComponent and move him like this:


		UNavigationSystem* const NavSys = UNavigationSystem::GetCurrent(this);
		if (NavSys)
		{
			NavSys->SimpleMoveToLocation(GetController(), SomeLocation);
                }

instead of using the AIController, but I haven’t had any success so far. The running animation is playing but the pawn just doesn’t move. I’ll post again if I found a solution.

DO you have a NavMesh placed?

@kamrann I think it might not be possible… Cause the camera wont work without a pawn being possessed. Any link to where he wrote?

Another related question. Attaching dummy pawn to the character like this doesn’t work



OwnedCharacter->AttachRootComponentTo(aPawn->GetRootComponent(), "root", EAttachLocation::SnapToTarget);

Do you move it to the characters location each tick?

I didn’t try to physically attach it. You can override the default camera behaviour in various ways, by setting the view target directly, or via a player camera manager.

My dummy pawn does nothing at all except relay commands to the AI controller. Like I say, I suspect you can cut it out entirely, but I’m afraid I don’t remember where I read it. I don’t think he provided any explanation of how to implement it anyway.

It is unecessary.
The pawn have PlayerController and simple using SimpleMoveToLocation to move with Navigation Mesh.
You can check out the TopDown Template of UE4 Engine.

This only works for single player games. Proxy is the easiest way achieve path finding in multiplayer games that don’t need client side prediction afaik.