Character/C++ Actor in editor is remembering an old version/Movement Component disappearing/wrong class, how to fix?

Hi. I have a very strange bug. A character I am making in CPP built off the default character is remembering settings from nearly a day ago after countless recompiles and project saves.

There are four states that I’ve seen.

The two from before recompiling after opening a project:

  1. Old character with old movement component shown. This is the most confusing one. The Manta Mov Comp hasn’t been a variable in roughly 18 hours. Again, I’ve recompiled/saved/etc countless times since the last time this was a variable.


2. Old character with no movement component.

Two states after recompiling:

  1. Character with proper variables
  2. Character with proper variables but no movement component

I’m not sure if it’s anything I’m doing but this issue is causing a ton of Failed to Cast as Actor crashes, and it’s incredibly tedious to try several times placing a character with all of the right settings only for the next time I open the project to redo it again.

Any ideas?

This issue is the closest I’ve seen: character movement disappeared - #16 by DarkEmbrace96 but I cannot just keep re-spawning the character and rolling the dice to see if it worked properly. Maybe there is some weird cache thing because of the old variable? I’m fairly new to UE5 so any help on this would be appreciated.

1 Like

I’m not 100% sure what you’re doing in your C++ code, but if you want to change/override the CharacterMovementComponent, there’s SetDefaultSubobjectClass for this reason.

I’m not sure if this is up-to-date with UE5, but it is explained in the old Wiki: Custom Character Movement Component | Unreal Engine Community Wiki

If you’re already following that, I apologize and hope someone else can help you.

2 Likes

Unfortunately I am already doing this :/. The issue seems to be with UE misremembering which Character I’m using. When I place a new one it uses the proper Character with this code, however every time I reopen the project (after saving/compiling etc) it revers back.

1 Like

Have you tried moving only the C++ Character to a completely new project? That way you could make sure if it’s related to something else in your project or to your code.

1 Like

You could also check if there are any Core Redirectors messing up things in your project:

1 Like

Haha, what an intimidating first sentence. It’s very possible I did some renaming a couple days ago and am only now noticing the consequences. I will have to look into the redirectors when I have some free time. Either way, for the project I’m working on, the default character won’t work anyways, so it’s no longer a major problem.

You could maybe try using the FObjectInitializer for your constructor to override the class of the component. I did this a while back for my AI controller to replace the PathFollowingComponent class:

AEnemyAIController::AEnemyAIController (const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass<UCrowdFollowingComponent(TEXT("PathFollowingComponent"))) {}

Try something like this to see if it works for you.

1 Like

I was using this already, the issue is UE5 would spontaneously decide to not use the component I had setup with the FObjectInitializer. Realistically it was easier to start writing my own pawn unfortunately, so I’m no longer pursuing a solution to this issue.