Skip to content

A system that saves positions of gameobjects in scene, so that you can recreate that scene with reusable pre-loaded gameobjects.

Notifications You must be signed in to change notification settings

davidkuc/Map-Objects-Save-System

Repository files navigation

Map Objects Save System

A system that saves positions of gameobjects in scene, so that you can recreate that scene with pre-loaded gameobjects. In the target project this system is meant to make gameobjects present in the scene reusable, so we don't have to load them for every new level in the game.

With this system, you can use just one scene, and change the level/ map by loading the appropriate objects with the saved positions, rotations etc. of that level. Which means that your levels would basically be prefabs, and your scene would change levels by loading objects and positions from those level prefabs.

Setting up the system

  1. In Resources/Level Manager create these objects

image

You can create the scriptable objects from the context menu --> Right click in project folder --> Scriptable Objects

image

  1. In the folder "Resources/Level Manager/Scene Objects" you need to add the gameobjects (prefabs) you wish to be reused through loaded levels. The gameobjects (prefabs) in the "Scene Objects" folder will be loaded into "LevelDataObjectsPool_SO", where you can set the amount of gameobjects to be instantiated when launching the game (field "Pool Size").

image

The LevelDataObjectsPool_SO will load the scene objects from "Scene Objects" folder on game start, but you can do it manually also --> Right click LevelDataObjectsPool_SO --> Level Manager --> Level Data Objects Pool --> Load All Scene Objects

  1. Now you need to create a level with the objects you put into the "Scene Objects" folder (IMPORTANT - ONLY OBJECTS FROM THE "Scene Objects" FOLDER WILL BE PROPERLY LOADED DURING RUNTIME!).

image

To save the level/ map --> Right click the level prefab/ gameobject in the scene --> Level Manager --> Generate Level Data

image

You will get a popup editor window to choose a name for the level. After writing the name press "Generate Level Data", your generated level file (Scriptable Object) will be in "Resources/Level Manager/Levels Data".

After generating a LevelData_SO, LevelDataList_SO will automatically update it's list of levels (this also happens on game start!;

You can also load the levels manually by --> Right click LevelDataList_SO --> Level Manager --> Level Data List --> Load All Levels Data

image

  1. Now you can load your level inside the game! After launching Play Mode you will notice a pool object in the scene hierarchy. Here you will have all the gameobjects instantiated from LevelDataObjectsPool_SO, in the amount you defined in that scriptable object.

image

To load the level of course you need to connect the system to your own game, but you can do it in the editor too! Make sure you have the LevelManager prefab inside the scene --> Click on LevelManager --> Right click Level Manager component --> Test Load Level (this will load the level from the LevelDataList_SO, with the index defined in "Level Index" under Debugging header in Level Manager component)

image

Your objects should appear in the scene! You can also unload the map by using the same index.


IMPORTANT NOTES

Every object inside the level/ map prefab needs to have it's prefab present in the "Scene Objects" folder, otherwise the system won't work.

Pay attention to the scene objects names, because this system uses strings as keys in dictionaries to compare scene objects.


If you need any help, contact me!

E-mail: davidkuc2@onet.pl || Discord: David Kuc#7866 || Facebook: https://www.facebook.com/McMudzynek

About

A system that saves positions of gameobjects in scene, so that you can recreate that scene with reusable pre-loaded gameobjects.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages