Character movement component being null

I’ve created a new character movement component and set it on c++, but after I did this I opened the blueprint actor and the details of the component are not showing and the component is being considered null, getting a lot of errors where it is referenced. To fix it I need to reparent my character to actor and when I reparent again to my character class it’s there, working, but when I do this I lost all the changes I made on the components and defaults values. There’s some other way to fix it?

2 Likes

Hello,

How did you setup the new Character Movement Component in C++? Screen shots of header and CPP files would be helpful for troubleshooting.

1 Like

On the Character Movement Component I’ve only override one function:

That’s how I’ve set the component on my character cpp file,

2 Likes

I think you need to override the the ObjectInitializer in your Character header.

For example, this is how I have a custom movement comp setup in my base character class:

Header:

public:
	// Sets default values for this character's properties
	ACustomCharacter(const class FObjectInitializer& ObjectInitializer);

CPP:

// Sets default values
ACustomCharacter::ACustomCharacter(const FObjectInitializer& ObjectInitializer)


	: Super(ObjectInitializer.SetDefaultSubobjectClass<UCustomCharacterMovementComponent>(
		ACharacter::CharacterMovementComponentName))

{

	// ==== Default Values ===== =====
	PrimaryActorTick.bCanEverTick = true;
	bReplicates = true;

	//Default Movement Values
	GetCharacterMovement()->MaxWalkSpeed = DefaultWalkSpeed;
	GetCharacterMovement()->MaxWalkSpeedCrouched = DefaultCrouchSpeed;
}
1 Like

I’ve done it too
image

1 Like

Hmm OK, not sure what is causing the issue then if your code matches mine. Can you show a screen shot of your components in the editor?

1 Like

The details panel is blank


And where it is referenced gets a lot of errors like it’s null

If I create a new actor it shows and work, but the ones that were created don’t. I’ve tried compile on the visual studio with the editor closed this time, because it happened before and I’ve compiled on the editor and thought it was the cause, but yet I have this error and the only way I found to fix is reparenting to actor and reparenting again to the class.

1 Like

So a couple things I think will be worth confirming:

  1. Is your UAirshipCharMovementComponent a child of CharacterMovementComponent?

  2. Let’s make sure the Character is actually using your Airship Movement Comp as the movement component so we can narrow down the issues.

Can you add a quick UE_LOG in BeginPlay of the character to verify?

I’m not at my Dev computer so typing from memory but should be something like this:

UE_LOG(LogTemp,Log,TEXT("Mvt Comp Class = %s),*GetCharacterMovement()->GetClass()->GetName())

That way we can make sure the character is using the right movement component

1 Like

It crashed on the characters I’ve created before, and one of these don’t have any code, I created it before changing the movement component just to test if this error would happen.

On a new character it works
image
On the base class from c++, without a blueprint class it works too

1 Like

And to confirm from above, your Airship Movement Comp inherits from UCharacterMovementComponent and not directly from UPawnMovementComponent or UMovementComponent?

1 Like

Yes inherits from UCharacterMovementComponent

1 Like

I’m not sure what’s causing the issue then without digging more into your project code. If it works on a clean character like you mentioned, I’m not sure why it’s not working on your AMainCharacter class.

Last thing I would try is deleting your interemediate, bininaries and sln file and rebuilding.

It does not work on a clean character, only work if I create a new one of this class, or reparent, the AMainCharacter class works fine. The actors that I created before compiling the change on the movement component dont work. And it’s not the code, because I only reparent and it work again, but I lose all my changes on the components and default settings.

I have a character only with the inherited components and no code that I’ve created before, and it doesn’t work

Try to reparent your Character BP to something other, like AActor and then back to AMainCharacter. I’ve stumbled over this in the past too, you set dbg breakpoints in the constructor → custom mvmt component is there. And then dbg breakpoint on begin play → it is gone. I think this is because of a glitch in the hot reload system.

3 Likes

The only way I found to fix it is by reparenting like you said, but I have to redo all my changes on the defaults values and components, which will be a great issue if this happens again when the project gets bigger.

That’s why I moved all Character functionality to cpp and use BP only for prototyping, if at all.

2 Likes

This worked for me, in case anyone else is struggling:
Open Blueprint
Class Settings
Parent Class (Change to “Actor”, or anything)
Parent Class, change back to “Character”.

3 Likes

I think compiling with the editor closed after making changes to constructors or header files prevents this issue from happening, but it doesn’t fix it if you’ve already compiled with the editor open before. You could try commenting out the changes, recompiling (with the editor closed), open the editor, close the editor, restore your changes, recompile again, and then open the editor and check your blueprints. I’m not sure if it will work, but it could be worth a shot.

Another potential fix for blueprints that have gotten messed up that might also prevent you from losing data the way you would if you reparent to a class higher up the inheritance chain (like reparenting a Character blueprint to Actor) would be to create a new blueprint with the same parent class as your existing blueprint, reparent your existing blueprint to the new blueprint, and then reparent it back to the original parent class. For example, if you made changes to the MyCharacter class and they weren’t showing in your MyCharacterBlueprint, you would create MyCharacterTempBlueprint parented to MyCharacter, reparent MyCharacterBlueprint to MyCharacterTempBlueprint, then reparent MyCharacterBlueprint back to MyCharacter.

This works for me, go to Class Settings, select for example actor and then Character again.

Thank you so, SO much for sharing this. Simple but elegant solution.