# Cast to Save Game is Failing

**URL:** <https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665>\
**Category:** Editor Scripting\
**Tags:** savegame, save-game, unreal-engine, Blueprint, question\
**Created:** [April 9, 2021, 3:42pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665 "2021-04-09T15:42:39Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_b3bc4d7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b3bc4d7a](https://forums.unrealengine.com/u/anonymous_user_b3bc4d7a)\
**Post date:** [April 9, 2021, 3:42pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/1 "2021-04-09T15:42:39Z")

</div>

Hi, I am a beginner to UE4 (I’ve only been using it for 4 months now, and I have no prior game engine knowledge), and I’ve run across a problem that I’ve failed to find a solution for in any of the forums/Q&As. I have been making a game, and I have a LOT of saving that happens. Last night, I renamed my project, I looked up how, and I changed the gamename URL thingy, and I changed the project name. When I enter the pop-up that asks which project I want to open, the name is accurate. But after I renamed the game, it seemed as though my save game wasn’t working. So I deleted the old one, and replaced all my references with a new one. I have accurately replaced all the variables and stuff, and the “load game from slot” code seems to work, but whenever my code gets to a “Cast to save game” node, the cast fails. I spent about an hour or two, going back to my files, and mass renaming my computer files so that anything I could change would be accurate name-wise. I deleted the old save .uassets and (.upex?) files, and as I mentioned above, the game is saving, it’s just failing when I cast. Here are some pics of my code:

![335402-codescreenshot.png]()

![335403-codescreenshot2.png]()

As you can see, I’ve added print strings to tell me whether the cast node is activated, and whether the cast fails or succeeds. Every time the code is run, the print strings say “yup1” and then “nope”, meaning the cast fails. I don’t know why though? I’m confirming that the load game from slot exists, it does exist, then the cast fails. I really need to get this bug fixed, since without save game data, my game is ruined. As a last resort, I guess I could replicate the game onto another project, where the renaming never happened, and the save game object doesn’t have any complications, but I would like to know how to fix this, in case it ever happens again.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b3bc4d7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b3bc4d7a](https://forums.unrealengine.com/u/anonymous_user_b3bc4d7a)\
**Post date:** [April 9, 2021, 3:49pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/2 "2021-04-09T15:49:06Z")

</div>

BTW, the SSC - Highscore variable is a save game object that is within my ThirdPersonCharacter Blueprint.

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [April 9, 2021, 4:53pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/3 "2021-04-09T16:53:32Z")

</div>

I don’t know the correct answer, but things that seem wrong to me are:

1. Casting after Create Save Game Object: you already create an object of the type you need. Casting here is unnecessary;

2. You’re saving the Game Save Object to a variable after loading, not after Casting. IDK if they conflict with each other in any way, but to me it seems that when you Create Save Game Object, you save your SpyRun\_Save type into a variable, but when you load game, you save a generic Save Game Object into the same variable.

For the debugging purposes, try making the same without the variable – just connect everything you need to your Create Save Game Object and Cast to SpyRun\_Save nodes.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b3bc4d7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b3bc4d7a](https://forums.unrealengine.com/u/anonymous_user_b3bc4d7a)\
**Post date:** [April 9, 2021, 5:12pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/4 "2021-04-09T17:12:17Z")

</div>

Okay, I’m new to saves and stuff so maybe I didn’t completely understand you, but I think I did what you said:

![335424-codescreenshot3.png]()

It declutters the code a lot, which is very helpful 0u0 ! Unfortunately, the cast is still failing 0n0.  
Also, all the code was working before, but I think something is wrong with my save game object files. The only difference between this code and my last code is that I use a different save game object, which I guess the reason I deleted the old one was because it wasn’t working, but that was only after I renamed the project.

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [April 9, 2021, 5:24pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/5 "2021-04-09T17:24:29Z")

</div>

Okay, another thing that comes to mind: the HighScoreData slot contains a save that isn’t “SpyRun\_Save”. If it’s so, your code will never create a new object to overwrite the existing one, and Cast will always fail.

My solution would be not to use the [Does Save Game Exist] node, and use Cast instead:

![335393-save.png]()

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b3bc4d7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b3bc4d7a](https://forums.unrealengine.com/u/anonymous_user_b3bc4d7a)\
**Post date:** [April 9, 2021, 5:46pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/6 "2021-04-09T17:46:34Z")

</div>

First of all, _face palms himself_ yes, the HighScoreData slot was originally under the previous save game, so that was probably one of my problems.  
Here is my new code:

![335426-codescreenshot4.png]()

However, it still doesn’t work, and every time I run the code, the “nope” string appears.

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [April 9, 2021, 5:51pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/7 "2021-04-09T17:51:01Z")

</div>

In the bottom branch of the code, you’re saving the object that has failed to Cast. You need to save the newly created object.

![335397-335426-codescreenshot4.png]()

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b3bc4d7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b3bc4d7a](https://forums.unrealengine.com/u/anonymous_user_b3bc4d7a)\
**Post date:** [April 9, 2021, 5:57pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/8 "2021-04-09T17:57:52Z")

</div>

YES, It works! Here is my final code:

![335427-codescreenshot5.png]()

So now all I need to do is reassign the slot names to the rest of the objects that require saves. It would appear that the way this happened, was that when I renamed the project, it glitched the save game, and then when I created a different save game object, it made the slots incompatible with that save. Thank you, Tuerer, I’ll start reassigning and decluttering my code right away! 0u0

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b3bc4d7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b3bc4d7a](https://forums.unrealengine.com/u/anonymous_user_b3bc4d7a)\
**Post date:** [April 9, 2021, 6:11pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/9 "2021-04-09T18:11:27Z")

</div>

When I renamed the project, the save files that went with it glitched. That’s why the old save game wasn’t working. When I created the new save game object, the game slots associated with the old save were unable to save to the new save. By reassigning my game slots, they start to work again, albeit at the loss of my previous data.

---

<div class="post-metadata">

**Author:** ![mikegarn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mikegarn](https://forums.unrealengine.com/u/mikegarn)\
**Post date:** [October 10, 2021, 5:50pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/10 "2021-10-10T17:50:56Z")

</div>

You totally just “saved” me a ton of troubleshooting royal force.

So just for a bit more clarity on the issue for anyone else with this problem. If you create a save game blueprint, then at any point after decide to rename your project, the old save game blueprint you created will no longer work. I’m assuming it keeps the directory of the previous project name, and the cast will fail because its no longer using the same file location. So my fix was to make new save game blueprints, and we’re back in business. Thanks again royal force 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b3bc4d7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b3bc4d7a](https://forums.unrealengine.com/u/anonymous_user_b3bc4d7a)\
**Post date:** [October 10, 2021, 6:36pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/11 "2021-10-10T18:36:56Z")

</div>

Your welcome 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2aa2a209](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2aa2a209](https://forums.unrealengine.com/u/anonymous_user_2aa2a209)\
**Post date:** [February 8, 2022, 8:28am UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/12 "2022-02-08T08:28:32Z")

</div>

Thanks for sharing.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b3bc4d7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b3bc4d7a](https://forums.unrealengine.com/u/anonymous_user_b3bc4d7a)\
**Post date:** [June 17, 2022, 2:29am UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/13 "2022-06-17T02:29:53Z")

</div>

Just a side note for those still experiencing trouble, after deleting the save game file, whether that be by directly deleting it, or deleting the save folder or save-game folder, make sure your code detects this by adding in a “does save game exist” node (or the corresponding c++ function I guess), and if the boolean returns false, then run some more code that creates a new save game. If you’re still experiencing trouble, you can message me and I’ll try my best to help out (Just don’t be surprised if it takes awhile for me to respond, my email is terrible at notifying me).

---

<div class="post-metadata">

**Author:** ![araz01](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/araz01/32/1028814_2.png) [@araz01](https://forums.unrealengine.com/u/araz01)\
**Post date:** [October 20, 2023, 1:13pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/14 "2023-10-20T13:13:28Z")

</div>

HAHAHAHAHAHAHAHAHHAHAHAHAHAAHHHAAHAHAHAHHAHAHAHHAHAAAHAHAHA, oooh, this is funny, yeah, i had the same problem, HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAAHHAHAHAA, aaah. very funny.

---

<div class="post-metadata">

**Author:** ![ser.man94](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ser.man94](https://forums.unrealengine.com/u/ser.man94)\
**Post date:** [May 30, 2024, 2:30pm UTC](https://forums.unrealengine.com/t/cast-to-save-game-is-failing/481665/15 "2024-05-30T14:30:57Z")

</div>

How you fixed?
