x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Save and Load Dead Enemies

Hello, I am trying to save enemies the player has killed in my save game object and when they are loaded they get destroyed immediately. I have tried several ways such as storing an IsDead? boolean in the enemy and then saving it to an IsEnemyDead? in the game save then when loaded if it is true it destroys the enemy but the casting to Enemy failed, I tried using an array but that didn't work either. Any Ideas?

Product Version: UE 4.20
Tags:
more ▼

asked Jan 28 '19 at 04:41 PM in Blueprint Scripting

avatar image

Mrminecraftwizz1
44 4 2 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

How do you spawn these enemies into the level? You must have some method that says Enemy "X" goes here, Enemy "Y" goes there. So whatever that method is, you should have an array of bools and when Enemy "X" is killed set the bool to true. Save this array out to your save game object. Then when you load the game back up have the spawner check the bool array and see if the enemy was killed, if yes, "spawn and destroy" or "skip" the index and move to the next. If they are statically placed, have a function in the level BP that checks this bool array against the enemies and if they are killed destroy the enemy instance.

more ▼

answered Jan 28 '19 at 05:36 PM

avatar image

Nebula Games Inc
5.4k 28 9 14

avatar image Mrminecraftwizz1 Jan 28 '19 at 10:00 PM

The Enemies are in the level already, I dragged and dropped them into the level (multiple of the same enemy as well). I'm not really sure I understand what you are talking about, I am new to arrays and saving and loading as is. Could you provide some screenshots if possible? Thanks for helping.

avatar image Nebula Games Inc Feb 01 '19 at 04:41 PM

Here, I made you a tutorial explaining how to do this. Hope it helps

https://youtu.be/Qe1K4Z2qME0

avatar image Mrminecraftwizz1 Feb 01 '19 at 05:36 PM

The Link says the video is unavailable.

Edit: Link started to work

avatar image Nebula Games Inc Feb 01 '19 at 05:41 PM

Sorry, def had the wrong release date on YouTube, try it now haha

avatar image Mrminecraftwizz1 Feb 18 '19 at 05:05 PM

I am having a bit of trouble implementing this into my project, I did follow the save and load tutorial by UnrealGaimeDev's RPG Tutorial Series (https://www.youtube.com/watch?v=xe1AEg7XyJw) How would I use the code in your tutorial in that project?

avatar image Nebula Games Inc Feb 18 '19 at 06:27 PM

What exactly are you having trouble with? I skimmed the link, it would seem you would just need to add everything I did into your character BP instead of how I did it with save/load separated from the player into the game instance and the level BP handling which actors were present at the time of saving. Because this "save/load" system is entirely contained within the player character I don't find it scalable. Placing it into the game instance would make it easier to keep track of things and not have everything that needs to be saved run through the player character. Imagine for every level if you want to save something the player character will have to have references to every single possible thing you want to save or create them at runtime. This is not a great way to handle saving "game state" for something like killed enemies which my tutorial is handling. For something like an inventory system that may not be an issue but for what you want to do I think this will be a headache later on. My advice is to create your "save/load" functionality within the game instance like I did and simply add UnrealGaime's inventory save functionality into the main save/load you create in a game instance. This way you can pass data from the player about the objects he holds/stats to the game instance and save them without having the player need to know how many enemies were killed in the level. The level BP can handle that and pass that info along to the game instance during a save.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question