BP forgets c++ parent after engine reload, can't reparent to it

Link to the question on the Unreal Course Community FB group: https://www.facebook.com/groups/unrealcourse/permalink/2692000887729860/?comment_id=2692009394395676

I created a c++ class derived from Pawn, called PlayerCamera. Then, I created a blueprint class based on it, BP_PlayerCamera, and set it as the default pawn class for my custom game mode (which derives from GameModeBase).

Everything executes and works fine until I close unreal and then re-open it: when I do that, BP_PlayerCamera isn’t the default pawn of the game mode anymore, and if I try opening the BP_PlayerCamera editor I get the following message:

“Blueprint could not be loaded because it derives from an invalid class. Check to make sure the parent class for this blueprint hasn’t been removed! Do you want to continue (it can crash the editor)?”

Of course the c++ class is still there, I didn’t remove it. Anyways, clicking on YES the blueprint editor opens and, in class settings, the parent class is set to None as the message says. If I try reparenting it, I can’t find my PlayerCamera c++ class among the ones in the list, even though it is still visible from the editor.

Here is the crazy part: if I delete the BP class, recreate it by right-clicking on the c++ class, and set it once again as the default pawn for the game mode, everything works fine again! The c++ class is found and parented correctly to the new BP, I can set this BP as the default pawn for my game mode, and the gameplay behavior is the intended one. Of course, if I close and restart the engine, the problem rises again and I am forced to repeat the same steps to make the BP work, which is very frustrating.

My question is: what the hell is going on? Could this be that some Unreal file somewhere is corrupted, causing my c++ class to not be found when the engine reloads? If so, is there a way to fix this?

Here is a list of things I tried and didn’t do anything:

  1. Give a different name to the BP (initially I thought the problem could be that there is an engine pre-built class called BP_PlayerCamera, but no)

  2. Create a completely new game mode

  3. Deleting the project and cloning it again to get rid of intermediate and binaries folders

  4. Deleting the BP and c++ classes along with the binaries folder as explained in lesson 90 of the course, recreating it and copy-pasting the old code in it and recompiling.

  5. Using git revert to make sure to wipe out everyting related to the PlayerCamera class and redoing everything from scratch.

I have other blueprints in my project that derive from custom c++ actors and I’ve never had this kind of issue. I created BP from c++ pawn classes in other projects before (ToonTanks) and nothing like this ever happened. What’s incredible to me is that I cannot find anyone online that had a similar problem.

Thanks for your patience and time guys, I really appreciate it! Let me know if you need screenshots, code snippets, link to gitlab project etc.

Could you send me your project to see if I can reproduce it on my end?

Use File > Package Project > Zip up project and send that.

1 Like

Hi Dan, thanks for answering me! :slight_smile:
I followed the procedure you wrote and produced the .zip file, where do you want me to send it? I tried to use the upload function available here, but only images are supported.

Any host like Google Drive, Dropbox, or similar.

Ok, which mail I should share the project with? info@gamedev.tv? I searched around but I can’t find your personal mail

dan@gamedev.tv. Or you could just PM.

Done, you should be able to see it :slight_smile:

Do you have reproducible steps?

Try this:

  1. destroy the BP_PlayerCamera
  2. recreate by right-clicking on the PlayerCamera c++ class
  3. Use the new BP as default pawn in the gamemode. You’ll see that clicking play everything is working, you can move the camera around, zoom etc.
  4. Now exit the engine and re-open it
  5. Click play: you’ll notice that something broke because the camera is in a completely different spot and it cannot be moved. If you check the gamemode you’ll see that the default pawn is set to none. Opening the BP_PlayerCamera you’ll see a message telling you that the BP has no parent. If you try re-parenting, you won’t find the c++ PlayerCamera among the possible options

Yep. I’m getting that and now to try and figure out why…

1 Like

I renamed the C++ class. Seems to be working now.

1 Like

Wow, so it was a naming problem, incredible… I excluded that because I thought Unreal stops c++ class creation when you try using an already existing name. But maybe that’s not the only case a name is not valid… strange; could this be classified as an engine bug? :thinking:

Anyways, thank you very much for your help Dan :smile: I’ll try renaming the class myself as soon as I have time to work on the project! One question since I’m here: is there a fast way to rename a c++ class without deleting and recreating it?

I just used VS Community’s* renaming to rename the class name. Then just change the filenames and two includes, the .generated.h in the header and the other in the .cpp. Finally, re-generate the project files and rebuild.

* Should be doable in VS Code as well with rename symbol (F2).

1 Like

Ok, it worked. Again, I’m shocked, Unreal shouldn’t allow users to create classes whose name is already taken (like in the image below, where I can’t define a class called Pawn because Pawn is an already taken name), but ok :man_shrugging:

Thanks again Dan, you’re the best! :smile:

I’m going to have a wild guess and say it’s because a pawn class had “camera” in the name? Either way this sounds like a bug and should be reported.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms