{"id":1922,"date":"2022-08-03T19:08:29","date_gmt":"2022-08-03T19:08:29","guid":{"rendered":"https:\/\/golemitegames.com\/?post_type=docs&#038;p=1922"},"modified":"2022-08-03T19:36:52","modified_gmt":"2022-08-03T19:36:52","password":"","slug":"saveloadgrid","status":"publish","type":"docs","link":"https:\/\/golemitegames.com\/index.php\/docs\/saveloadgrid\/","title":{"rendered":"SaveLoadGrid"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">public static void SaveCurrentGrid (GridSquare gridSquare)<\/h2>\n\n\n\n<p>Saves the given <strong>gridSquare<\/strong> to disk under <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>string path = $&quot;{Application.persistentDataPath}\/{SceneManager.GetActiveScene().name}&quot;;<\/code><\/pre><\/div>\n\n\n\n<p>The file name will contain the <strong>gridSquare.name<\/strong> plus its <strong>id<\/strong>. <\/p>\n\n\n\n<p class=\"has-background-color has-text-color\">Note. This save path is relevent <em>only<\/em> to the user. Any save files shipped with the product will be redundent as Application.persistantDataPath is different for each OS. To save a file that can be shipped, see <strong>SavePreconfiguration<\/strong>. <\/p>\n\n\n\n<p>All placed object data is saved using the <strong>GridObject<\/strong> class along with the <strong>GridData<\/strong> class and is converted to binary. <\/p>\n\n\n\n<p>Being a static class this can be called from anywhere without reference. <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>public GridSquare gridSquare;\npublic Button saveBtn;\n\nvoid Start() \n{\n    saveBtn.onClick.AddListener(() =&gt; \n    {\n         \/\/Saves the given GridSquare\n         SaveLoadGrid.SaveCurrentGrid(gridSquare);\n    });\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">public static GridData LoadCurrentGrid(GridSquare gridSquare)<\/h2>\n\n\n\n<p>Finds and loads the given <strong>gridSquare<\/strong> looking for this file<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>string filePath = $&quot;{Application.persistentDataPath}\/{SceneManager.GetActiveScene().name}\/{gridSquare.name.Replace(&quot; &quot;, string.Empty)}-{id}.data&quot;;<\/code><\/pre><\/div>\n\n\n\n<p>If no save file is found, this function will also try and look for a <strong>preconfig<\/strong> named.  <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>string configFilePath = $&quot;{Application.dataPath}\/GolemiteGames\/GridBuilder2\/PreConfig\/{SceneManager.GetActiveScene().name}\/{gridSquare.name.Replace(&quot; &quot;, string.Empty)}-{id}.preconfig&quot;;<\/code><\/pre><\/div>\n\n\n\n<p>You can load the same way as you saved.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>public GridSquare gridSquare;\npublic Button loadBtn;\n\nvoid Start() \n{\n    loadBtn.onClick.AddListener(() =&gt; \n    {\n         \/\/Saves the given GridSquare\n         SaveLoadGrid.LoadCurrentGrid(gridSquare);\n    });\n}<\/code><\/pre><\/div>\n\n\n\n<p>If it is confusing which file will load, take a look at the <a href=\"https:\/\/golemitegames.com\/index.php\/grid-builder-2-loading-flow-chart\/\" title=\"flow chart\">flow chart<\/a> explaination. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">public static void DeleteCurrentGridSaveData(GridSquare gridSquare)<\/h2>\n\n\n\n<p>Removes the given <strong>gridSquare<\/strong>&#8216;s save file from disk if there is one. <\/p>\n\n\n\n<p class=\"has-background-color has-text-color\">Be careful using this as there is no backup of this file. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">public static void SavePreconfiguration(GridSquare gridSquare)<\/h2>\n\n\n\n<p>This will save your current <strong>preconfiguration<\/strong> to disk under<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>string path = $&quot;{Application.dataPath}\/GolemiteGames\/GridBuilder2\/PreConfig\/{SceneManager.GetActiveScene().name}&quot;;<\/code><\/pre><\/div>\n\n\n\n<p>This is used primarily in the <strong>GridSquare<\/strong> inspector but can also be called from elsewhere. <\/p>\n\n\n\n<p class=\"has-background-color has-text-color\">Note. The application has to be in <strong>Play<\/strong> mode for this method to work. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">public static GridData LoadPreconfiguration(GridSquare gridSquare)<\/h2>\n\n\n\n<p>Loads the <strong>gridSquare preconfig<\/strong> if there is one, looks under<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>string configFilePath = $&quot;{Application.dataPath}\/GolemiteGames\/GridBuilder2\/PreConfig\/{SceneManager.GetActiveScene().name}\/{gridSquare.name.Replace(&quot; &quot;, string.Empty)}-{id}.preconfig&quot;;<\/code><\/pre><\/div>\n\n\n\n<p>You can set this up easily via the inspector to load the <strong>preconfig<\/strong> on start or you can call it yourself. <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>public GridSquare gridSquare;\nvoid Start() \n{\n    SaveLoadGrid.LoadPreconfiguration(gridSquare);\n}<\/code><\/pre><\/div>\n\n\n\n<p>If it is confusing which file will load, take a look at the <a href=\"https:\/\/golemitegames.com\/index.php\/grid-builder-2-loading-flow-chart\/\" title=\"flow chart\">flow chart<\/a> explaination. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\">public static void DeletePreconfiguration(GridSquare gridSquare)<\/h2>\n\n\n\n<p>Removes the <strong>preconfig<\/strong> file for the given <strong>gridSquare<\/strong> if one is found. <\/p>\n\n\n\n<p class=\"has-background-color has-text-color\">Be careful using this as there is no backup of this file. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>public static void SaveCurrentGrid (GridSquare gridSquare) Saves the given gridSquare to disk under The file name will contain the gridSquare.name plus its id. Note. This save path is relevent only to the user. Any save files shipped with the product will be redundent as Application.persistantDataPath is different for each OS. To save a file that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"doc_category":[45],"doc_tag":[],"class_list":["post-1922","docs","type-docs","status-publish","hentry","doc_category-scripting-gridbuilder2"],"acf":[],"aioseo_notices":[],"year_month":"2026-04","word_count":439,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"rickitz5h","author_nicename":"rickitz5h","author_url":"https:\/\/golemitegames.com\/index.php\/author\/rickitz5h\/"},"doc_category_info":[{"term_name":"Scripting","term_url":"https:\/\/golemitegames.com\/index.php\/docs-category\/scripting-gridbuilder2\/"}],"doc_tag_info":[],"_links":{"self":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/comments?post=1922"}],"version-history":[{"count":15,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1922\/revisions"}],"predecessor-version":[{"id":1937,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1922\/revisions\/1937"}],"wp:attachment":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/media?parent=1922"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/doc_category?post=1922"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/doc_tag?post=1922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}