"Cannot replace existing object of a different class" with two objects of the same class error

Hi! I’m a game dev student working with a team on a senior project.

We are using Unreal Engine 5.6.1 to develop our game, with Perforce for version control.
Our plugins are Inkpot and Yaml, used for our dialogue system and document system respectively. We also have a custom-made plugin that’s not in use so it shouldn’t affect anything.

If we Get Latest from Perforce and attempt packaging (for Windows, all of us are on Windows), it successfully builds, but our code changes are not present, resulting in bugs in-game. Upon compiling in-editor using the button in the lower right, the following error appears:

BABGameInstance is the Game Instance we created, a child of the built-in GameInstance class. It is declared as the Game Instance in Project Settings. It contains a few variables that we want to preserve between levels, but no functions. Past versions of our project demonstrated that BABGameInstance works exactly as intended.

Summary

This text will be hidden

Summary

This text will be hidden

We’ve tried checking our Project settings for our save blueprint, going through our configuration files (DefaultEditor.ini, DefaultEditorPerProjectUserSettings.ini, DefaultEngine.ini, DefaultGame.ini, and DefaultInput.ini). We’ve also tried renaming the BABGameInstance class in case something wasn’t being synced between the files and the editor, but changing the name just changed the name in the error as well. We’ve also done the “Update Redirector References” option in-editor on our Content folder. We’ve gone through our files and checked if we had any duplicate declarations, which we don’t - we only get a reference to the BABGameInstance. We have also cleaned the Visual Studio solution itself with no luck. We’ve also adjusted some settings in Perforce, but we’re reasonably confident that the issue is unrelated to our version control software.

It’s unclear if this is related, but upon getting the latest code from Perforce, the project often will not run until we delete Saved, Intermediate, and Binaries and then regenerate project files, giving the same error as seen in the packaging error.

Here are links to Google Drive files of the AppData/Roaming/Unreal Engine/AutomationTool/Logs/C+UE_5.6/Log.txt from the packaging error and our most recent Saved/Logs/TestProject.log from the initial project opening crash.

Thank you!

Hello there @qksjeli!

Checking through your logs with my peers, the “Cannot replace existing object of a different class” means that UE is looking for two different definitions of the same class, which would need to exist at the same time. In most cases, this confusion stirs from stale metadata. Your log shows that packaging completes succesfully, but the process fails in the final stretch due the mismatch.

You have already cleared cache, but there are a few elements that need to be deleted as well for a full clear. Since you and your team are working with Perforce, all users should perform the following actions:

  • From the project’s directory, delete the following folders:

    • /Binaries
    • /Intermediate
    • /Saved
    • /DerivedDataCache
    • /.vs
  • And from your app data, delete the local DDC as well, at *…AppData\Local\UnrealEngine\Common\DerivedDataCache*

  • After that, re-generate your project in both VS and UE

  • Finally, with a clean slate, check for any remaining redirectors or broken references to BABGameInstance, and test your build again

1 Like

Hi @brs-sebascova! Thank you so much for your reply - I followed your instructions to perform a full clear, but I still have the same error. Any references to BABGameInstance seem to be appropriate (we have some in Blueprints and in C++, but only one C++ BABGameInstance class), they all call GetGameInstance() and then cast the GameInstance to a BABGameInstance like so:

UGameInstance* tempGameInstance = GetGameInstance(); gameInstance = Cast<UBABGameInstance>(tempGameInstance);

I can’t find any unusual references to BABGameInstance or GameInstance. Inkpot does have a reference to a regular GameInstance, but I’m not sure if that would cause the problem?

Any other advice would be greatly appreciated. Thank you very much!