Enlightenment about MovementComponent?

Hi,

I would like more information about the MovementComponent system, it’s totally foggy at the moment. The more I try to understand how things work for Character the more I’m confused. At first I found the PlayerMove and UpdateRotation functions inside the PlayerController header which made me think that the code was similar to the one in UE3.

However, after this, I started to get totally lost. What is the StartMoving function doing ? From my test, it’s called only once when the player spawn, so it’s used to initialize something, but what ? There is no information about this.

Regarding the platformer example, it rests on the physWalking functions and override some things, ok, but after it calls the Super version which make me unable to understand why there is a physWalking function in the custom MovementComponent, is this a sort of state ? Who calls it ? What is done inside it exactly ?

I’m going nowhere currently, I wouldn’t mind some help (or better : some cpp files) about this because it’s totally impossible to understand the system with only the headers and the tiny documentation. I understand totally that the code is not yet ready, but I prefer updating my code every beta that running in the dark and screaming to any functions to see if there is one that will respond to me.

:insert sad smiley here:


By the way, I found this page : https://rocket.unrealengine.com/docs/ue4/INT/Resources/Examples/PlatformerGame/index.html

It’s missing from this list : https://rocket.unrealengine.com/docs/ue4/INT/Resources/Examples/index.html

Unrelated to the main topic, but I have reported the documentation inconsistency you mentioned. Thanks for finding it.

Thanks ! (Yes, this is a malicious bump for my questions below.)

PlayerController by default has 2 states ‘moving’ and ‘spectating’. StartMoving just puts you into the ‘moving’ state. PlayerMove has actually gone from PC in the latest beta. All of the actual logic concerning how the pawn moves is now in the pawn or movementcomponent class you are using. This should make it much easier to make different games than it was in UE3, but still be able to build on our core walking Character class if that is what you need.

We do have plans to make it much easier to add additional states to the CharacterMovementComponent - using a name rather than an enum. We are certainly going to give out all the source (for reference) for classes like PlayerController, Pawn and CharacterMovementComponent. Hopefully in the next beta.

If you can give us some more details on what you are trying to achieve, we maybe be able to improve this process further.

Thanks for the answer a Sunday ! :slight_smile:

You are moving the movements functions (which are outside of the MovementComponent) to the Pawn, so why keeping the “Controller” class name ? It’s not its purpose anymore ? In UE3 it was clear because you were able to differentiate pawn (Visual player) with the PlayerController (Controls/States). How would you resume this in Rocket now (regarding the next beta I mean) ?

What I’m trying to do ? Simply this : UDK | EXIL : Sprint Camera and FOV - YouTube
Being able to move my camera and my character independently. Currently I was able to change the camera rotation by overriding the UpdateRotation inside the PlayerControler class. However I’m stuck with the character rotation. Since I don’t know where/who calls the movement functions, it’s hard to override something (I need to compute myself the Acceleration vector with the inputs and update the Pawn.FaceDirection regarding this).

I started overriding PlayerMove because in sounded like the old UE3 functions, but ProcessMove disappeared so I’m trying to see who handles the equivalent of Pawn.Acceleration and who read the inputs to compute them as an acceleration vector (in UE3 it was PlayerMove).

Being able to do this will make me able to change my future state I guess (like switching between some physics, walking state and swimming, and so on).

Thanks for the answer a Sunday ! :slight_smile:

We know you guys sometimes only get a chance to work on Rocket at the weekend, so we like to check if we get a minute :slight_smile:

One thing we are trying to refactor in UE4 is keeping code specific to the Pawn you are possessing out of the Controller. This has several benefits:

  • Stops the Controller class becoming massive (the union of all actions you can do with any pawn in the game).
  • Keeps the code in one place rather than being split across Pawn and Controller.
  • Allows us to keep the base PlayerController class cleaner, making less assumptions about the kind of game you are making.

Controller is still a very important class! Anything related to the player that doesn’t change when you possess different Pawns belongs there. Also AI.

What I’m trying to do ? Simply this : UDK | EXIL : Sprint Camera and FOV - YouTube

Cool video! You will be pleased to know that the next update of the Third Person template looks a lot like that :slight_smile: We changed it to ‘camera relative’ controls, which required us making a few changes to the CharacterMovementComponent, but we think this will make it a lot more flexible.

There are 3 bools in Pawn now (bUseControllerRotationPitch/Yaw/Roll - not sure if these are in your build) which you can set if you want the pawn locked to the controller rotation. If you do not want that, set them to false and you can control the Pawn’s rotation yourself (in tick, for example).

Thanks for the answer, I took the time today to dig a bit more. I found the booleans that you mention. However, since I’m overriding the UpdateRotation function I don’t need them (they don’t have any effect anyway).

I was trying to setup my own inherited UMovementComp_Character class, inspired by the one inside the platformer sample. However I don’t understand how the class is referenced inside the Character class. The only hint I found is inside the Constructor :

APlatformerCharacter::APlatformerCharacter(const class FPostConstructInitializeProperties& PCIP) 
	: Super(PCIP.SetDefaultSubobjectClass(TEXT("CharMoveComp")))
{
}

I must admit this is quite strange, what is happening here ? Also, regarding the sample of this Beta 3, it seems that nobody is calling the overrided physWalking function since the CharacterComponent is not referenced.

What could be the best way to call my own character movement component ? To replace the default one created inside the ACharacter class (called CharacterMovement).

Same thing with the Shooter example, there is Character Movement Component class, but nobody reference it ? Why ?


While I understand that you are trying to give more usefull samples, I see one big problem at the moment : they are heavily based on the original class which make us unable to understand correctly the code. My goal here is not only to setup a simple character/camera, this is the base of all my gameplay. Being able to setup the walking correctly AND manually will make me able to setup my own “states” later for walking on walls and climbing ledges.

That’s why I’m trying so hard to understand the new system. Sorry if I sound negative, but the current answers sound more like “use this, it will be okay” than helping me understand how things works. I hope you understand.

Okay, I got almost what I wanted working. Almost, because I still block on how to add my own MovementComponent class and override some functions (especially CalcVelocity() ).

I didn’t found how to reference my new class, even as a blueprint. A got an error during the compilation about “No operator found which takes a right-hand operand of type 'UClass *” about “SubobjectType=UMovementCom_Character”.

	static ConstructorHelpers::FObjectFinder UMovement(TEXT("Blueprint'/Game/EXIL/gameplay_base/bp_class_Movement.bp_class_Movement'"));
	if (UMovement.Object != NULL)
	{
		CharacterMovement = (UClass*)UMovement.Object->GeneratedClass;
	}

By the way, I would like some explanation about TSubobjectPtr, it seems specific about the Unreal Engine and I don’t understand it. Ex :

TSubobjectPtr CharacterMovement;

Could it be possible to have some information ? Thanks.

Sorry, this post got lost in the big thread!

You cannot create new component classes in blueprints, so I assume you are creating this new CharacterMovementComponent subclass in C++? In which case you don’t need any of the ConstructorHelpers stuff. If you want to change the class of an existing component you do:

AMyCharacter::AMyCharacter(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP.SetDefaultSubobjectClass(ACharacter::CharacterMovementComponentName))
{

Hope that helps!

Unfortunately, there is something that I’m not udnerstanding. Here is my code :

AEXILCharacter::AEXILCharacter(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP.SetDefaultSubobjectClass(ACharacter::CharacterMovement))
{

My compilation :

Module.EXIL.cpp
C:\UDK\Rocket\Projects\EXIL\Source\EXIL\Private\EXILCharacter.cpp(6) : error C26
64: 'const FPostConstructInitializeProperties &FPostConstructInitializePropertie
s::SetDefaultSubobjectClass(FName) const' : cannot conve
rt parameter 1 from 'TSubobjectPtr' to 'FName'
        with
        [
            SubobjectType=UMovementComp_Character
        ]
        No user-defined-conversion operator available that can perform this conv
ersion, or the operator cannot be called
-------- End Detailed Actions Stats --------------------------------------------
---------------
ERROR: UBT ERROR: Failed to produce item: C:\UDK\Rocket\Projects\EXIL\Intermedia
te\BuildData\EXIL\Win64\Development\RocketEditor-EXIL.exp
Cumulative action seconds (8 processors): 0,00 building projects, 8,72 compiling
, 0,00 creating app bundles, 0,00 generating debug info, 0,00 linking, 0,00 othe
r
UBT execution time: 12,22 seconds

Obviously, the class is expecting a FName, but how do you declare it since you are inside the Constructor ? Also, here I’m just trying to override the CharacterMovement component, but what if I would like to override the CapsuleComponent too ? The current syntax is not really self-explanatory and seems limited to one override (or it’s probaby something that I don’t know about C++).

Ho, you are referencing an FName variable, but I guess this variable doesn’t exist in my current build.

Ah sorry, the component name is “CharMoveComp”. As you say, it uses a static variable in the next release to make this easier. Also we will be giving out the source to several classes, including Character and CharacterMovementComponent.

How does the character rotate based on acceleration relative to camera location?

I believe you have to override the UpdateRotation, PlayerMove in you PlayerController and maybe even the FaceRotation fucntion of your Character.

I’m working on this, but I wasn’t able to override the CalcVelocity function until now (which was making some conflicts with my previous override).

U dont need calcvelocity. It wont work anyways cuz it doesnt return acceleration. Do GetMovementComponent()->Acceleration that what i did

Hmmm, would you mind sharing how you use the Acceleration vector ? I tried to use it with the FaceRotation function but it just make my Character turning on himself like a crazy top.

Well just for test i did it without updaterotation so i dunno. But wen i did that it would face only forward and not follow my camera rotation. Im going to wait for the bOrientToMovement

In the upcoming beta there is a bOrientToMovement option that I think will do exactly what you want.

Ah thanks that will be helpful please.