How is PCIP intended to be used?

Hello guys, I recently made the jump to UE4 from UE3. At the moment I am trying to implement a new movement component in which the player is a flying camera. I started with the basic first person shooter template but I am stuck at trying to modify it in order to implement the behavior I desire. The problem is that I am confused on how I would tell my character to use my custom movement component instead of the one that the Character class sets, the CharacterMovementComponent. One of the entries on the wiki says to do it in the following form:

AVictoryPlayerCharacterBase::AVictoryPlayerCharacterBase(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP.SetDefaultSubobjectClass<UVictoryCharMoveComp>(ACharacter::CharacterMovementComponentName))

I am not sure if what is happening in the initialization list is how they intended PCIP to be used when we want to override the class that we use for the character movement. The way in which i was thinking to override the class that is used as the default movement is the following:

  1. Let the super class do what it wants to do
  2. Inside of the custom character class delete the Character Movement that was created by the Super class
  3. Create our custom movement class and assign it to the the variable that the Super class used to store a handle to the movement class.

What is yall’s opinion? How exactly is PCIP intended to be used?

Thanks

Hi Jesse,

from my experience with the code base it seems that unreal wants you to define the name of your sub-class of the CharacterMovement as shown in the wiki. You shall adapt the information stored in PCIP in the initialization list, or more accurate in the parameter list of the super constructor. So that it contains the class name of your implementation of the CharacterMovementComponent before the constructor of Character is called.

The return-type of this method is the adapted PCIP itself, such that you can perform multiple adaptations inside the parameter list.

So what you’re actually doing when u stick to the way in the wiki is:

  1. Set the Type Information (class name) of your implementation of CharacterMovement
  2. Let the super class allocate memory and initialize it’s defaults for the CharacterMovement
  3. Let your custom class adapt those defaults and set special attributes for your Movement implementation

One advantage is that you spare one memory de-allocation and one allocation. Another advantage is that the attributes of the subclass are initialized in a meaningful manner. There might be more drawbacks that I’m not aware of yet but your solution should also work.

Thanks DarthB,

after thinking more about it, I realized that there could be many drawbacks to doing it the way I was intending to, just as you noticed. Therefore, I decided to go with what the wiki said and do it that way. Your answer was actually helpful on understanding what that line of code does and why it works.

Yeah, side effects could potentially happen from initializing your super state to one thing, you can’t rely on changing variables after the fact.