{"id":680,"date":"2026-05-15T19:57:09","date_gmt":"2026-05-15T19:57:09","guid":{"rendered":"https:\/\/sites.wsagames.com\/et4g23-yr3\/?p=680"},"modified":"2026-05-15T19:57:09","modified_gmt":"2026-05-15T19:57:09","slug":"player-manager","status":"publish","type":"post","link":"https:\/\/sites.wsagames.com\/et4g23-yr3\/2026\/05\/15\/player-manager\/","title":{"rendered":"Player Manager"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">After <a href=\"https:\/\/sites.wsagames.com\/et4g23-yr3\/2026\/05\/15\/developing-level-2\/\">developing Level 2<\/a>, I realised I needed a way to store the information about what abilities the player has unlocked from scene to scene. However, this cannot be done with the Player gameobject as that would cause the player to spawn in weird places from scene to scene.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To fix this I created a created a &#8216;Player Manager&#8217; <strong>singleton <\/strong>that is preserved even when transitioning scenes:<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6aca2e8d71cea&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6aca2e8d71cea\" class=\"wp-block-image aligncenter size-full wp-lightbox-container\"><img fetchpriority=\"high\" decoding=\"async\" width=\"359\" height=\"215\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-content\/uploads\/sites\/41\/2026\/05\/image-70.png\" alt=\"\" class=\"wp-image-681\" srcset=\"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-content\/uploads\/sites\/41\/2026\/05\/image-70.png 359w, https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-content\/uploads\/sites\/41\/2026\/05\/image-70-300x180.png 300w\" sizes=\"(max-width: 359px) 100vw, 359px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">DontDestroyOnLoad() prevents the PlayerManager from being destroyed when the scene it comes from is unloaded.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Singleton<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A\u00a0creational design pattern\u00a0that lets you ensure that a class has only one instance, while providing a global access point to this instance.<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6aca2e8d7276f&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6aca2e8d7276f\" class=\"wp-block-image aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"316\" height=\"144\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-content\/uploads\/sites\/41\/2026\/05\/image-71.png\" alt=\"\" class=\"wp-image-682\" srcset=\"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-content\/uploads\/sites\/41\/2026\/05\/image-71.png 316w, https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-content\/uploads\/sites\/41\/2026\/05\/image-71-300x137.png 300w\" sizes=\"(max-width: 316px) 100vw, 316px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This Player Manager script is then able to store key information about the player&#8217;s progression that needs to be stored regardless of scene. In this case, they are stored in the form of bools.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The playercontroller script is then able to check the value of these bools and then unlock the player&#8217;s abilities correspondingly:<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6aca2e8d72da8&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6aca2e8d72da8\" class=\"wp-block-image aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"425\" height=\"543\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-content\/uploads\/sites\/41\/2026\/05\/image-72.png\" alt=\"\" class=\"wp-image-683\" srcset=\"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-content\/uploads\/sites\/41\/2026\/05\/image-72.png 425w, https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-content\/uploads\/sites\/41\/2026\/05\/image-72-235x300.png 235w\" sizes=\"(max-width: 425px) 100vw, 425px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><figcaption class=\"wp-element-caption\">HandleAbilityUnlocks() is called in Update()<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This PlayerManager will have a lot of use-cases and will be vital to the game functioning as intended.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After developing Level 2, I realised I needed a way to store the information about what abilities the player has unlocked from scene to scene. However, this cannot be done with the Player gameobject as that would cause the player to spawn in weird places from scene to scene. To fix this I created a [&hellip;]<\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-680","post","type-post","status-publish","format-standard","hentry","category-sprint-2"],"_links":{"self":[{"href":"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-json\/wp\/v2\/posts\/680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-json\/wp\/v2\/comments?post=680"}],"version-history":[{"count":1,"href":"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-json\/wp\/v2\/posts\/680\/revisions"}],"predecessor-version":[{"id":684,"href":"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-json\/wp\/v2\/posts\/680\/revisions\/684"}],"wp:attachment":[{"href":"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-json\/wp\/v2\/media?parent=680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-json\/wp\/v2\/categories?post=680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.wsagames.com\/et4g23-yr3\/wp-json\/wp\/v2\/tags?post=680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}