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?
Hello,
How did you setup the new Character Movement Component in C++? Screen shots of header and CPP files would be helpful for troubleshooting.
On the Character Movement Component I’ve only override one function:
That’s how I’ve set the component on my character cpp file,
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;
}
I’ve done it too
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?
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.
So a couple things I think will be worth confirming:
-
Is your UAirshipCharMovementComponent a child of CharacterMovementComponent?
-
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
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
On the base class from c++, without a blueprint class it works too
And to confirm from above, your Airship Movement Comp inherits from UCharacterMovementComponent and not directly from UPawnMovementComponent or UMovementComponent?
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.
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.