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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Best way to implement a level-chain

Hi everybody

I'm stuck with an architectural problem: In my game I want a central way of managing levels. More concretely: I want to organize my levels into chapters and store some additional information per chapter and per level (which I need to be able to persist on disk later on, since the information will change when the player completes a level). The structure would look something like this:

Chapter:

  • Chaptername (FString)

  • points needed to unlock the chapter (int32)

  • array of levels belonging to the chapter (TArray)

Level:

  • Time taken to solve the level (float)

  • primary score (int32)

  • secondary score (int32)

  • Level name (FName, corresponds to the name of an existing levelasset)

Now I need to store an array of chapters somewhere and the place that appeared best for that in my opinion was the gamemode, but I'm not bound to that decision. It needs to be, however, in a globally accessible place (across levels). I want to be able to edit the array of chapters in the editor (so it's easy for artists to add new levels without the need to go and change code) which means the array needs to be a UProperty.

Do you have a recommendation on how I could/should implement this? I have tried creating FStructs but I wasn't able to use them as properties (the property didn't get persisted and was reset whenever I reloaded the project; I'm quite confused about this behavior because I used the BlueprintType specifier in the FStruct macro). Then I created UObjects but I can't really use something which needs to be instanced, since I'm not able to create an instance of an object in the editor (at least not of a UObject; and actor types need to be placed in a specific level wich doesn't work either).

I'm very interested in your thoughts about this problem and would be enormously glad if you could share your experience, in case you implemented similar logic! Thank you in advance!

Product Version: UE 4.17
Tags:
more ▼

asked Sep 25 '17 at 07:13 PM in C++ Programming

avatar image

Multimodcrafter
31 2 3 5

avatar image Multimodcrafter Sep 25 '17 at 07:15 PM

Just FYI: when I tried to use FStructs, I placed the definition inside the gamemode header. Could that be the problem for it not being persisted? Where else should one generally place struct definitions?

avatar image Dune Sep 27 '17 at 03:26 PM

For persistent data while the game is running, check out the Game Instance. You can access this from anywhere with GetGameInstance() call and this persists through level loads.

You may then also want to check out the USaveGame class - Which allows you to easily save data in a binary file to disk.

avatar image Multimodcrafter Sep 27 '17 at 06:27 PM

Thanks a lot for the remark! I will definitely look into those things!

avatar image Multimodcrafter Sep 27 '17 at 06:55 PM

Hey it looks like I've had derped once again. I got it working with the struct now! But I moved everything to the game instance so please change your comment into an answer so I can give you credit for solving this problem.

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

1 answer: sort voted first

For constant level information, you can store that in a Table of custom Struct. Then for dynamic save information, you must create a SaveGame object, inside you can store any structs or primitive data. You cannot save a whole object, like your Player. So instead, you should pull the important information you want to save from any object, and store it in a struct or list of structs.

For example, if you want to save the progress of all your levels. Maintain an array of structs that hold that data in you GameMode, then send that to your SaveGame data before you save. Or just maintain it in your save object, just be sure to update it when things change, so it can be saved!

Below I'll show how I store my linear game's data:

  • My constant level data struct LevelStruct. In this, I store information that is shown on the main menu. Struct

  • My Levels table Levels. Holds a list of my LevelStruct with different values for each level. Table

  • My dynamic save data FinishedLevels. In my game, I only need to store whether or not the player reached/completed a level. So it stores two maps of Level-ID's paired with with whether or not they were reached or completed. This object is what is saved, and loaded. Save Game

  • I call this save function any time the values change, and I only ever have one persistent save. You could save multiple files in different slots. Save Data

  • Here's how I load my save data. And if the location doesn't exist, in my game I just make a new blank one. But your needs may be different. You may only want to create a new save data object, when a player starts a new game. alt text

more ▼

answered Sep 27 '17 at 07:56 PM

avatar image

BenVlodgi
2.1k 38 17 52

avatar image Multimodcrafter Sep 28 '17 at 06:14 PM

Thanks a lot for your detailed explanation! I didn't know about tables so that's definitely a plus for your answer. I guess i will, however go with the fully fledged GameInstance version that @Dune mentioned, since all of my data that i store - appart from the names - is dynamic (in comparison to your solution wich has static and dynamic properties separated)

avatar image BenVlodgi Sep 28 '17 at 06:53 PM

Happy to help.

I suggest you still make a table of constant level information for devs to specify. Stuff like Level Name, Level ID, Number of Required Shards to Complete, Next Level ID. This way when you create a new SaveGame from scratch, you can pull this data from the table. And your artists can add entries or edit entries of the table when they design levels.

avatar image Multimodcrafter Sep 28 '17 at 08:17 PM

the table cannot be edited dynamically though right?

(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