Forum begins after the advertisement:
[Part 7] Map UI problems
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 7] Map UI problems
- This topic has 10 replies, 2 voices, and was last updated 7 months, 2 weeks ago by Anuk Thotawatta.
-
AuthorPosts
-
April 24, 2024 at 6:33 pm #14253::
My maps are not named in number order. Instead they are named like this:
View post on imgur.com
And my mapManager.cs :
<code>using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class MapManager : MonoBehaviour { // Start is called before the first frame update [SerializeField] GameObject[] maps; Coffin coffin; private void OnEnable() { coffin = FindObjectOfType<Coffin>(); if(coffin != null){ if(coffin.interacted){ UpdateMap(); } } } void UpdateMap(){ var savedScenes = SaveData.Instance.sceneNames; for(int i=0;i<maps.Length;i++){ if(savedScenes.Contains("Cave_"+i+1)){ maps[i].SetActive(true); } else{ maps[i].SetActive(false); } } } } </code>
how do i modify this code to work with my naming system? i Also have alot of interconnected scenes. will the above code work if i named them in order?
April 25, 2024 at 12:52 am #14254::Right now, the code should only accept naming systems of “Cave_
number
“. It should not be able to take your style of naming the caves.First off, I believe this is incorrect.
void UpdateMap(){ var savedScenes = SaveData.Instance.sceneNames; for(int i=0;i < maps.Length; i++){ if(savedScenes.Contains("Cave_"+
i+1(i + 1))){ maps[i].SetActive(true); } else{ maps[i].SetActive(false); } } }If you want to modify the code, one simple solution is to; First, rename your subcaves from “Cave_1.1” > “Cave_1.2”, to something like “FirstCave_1” > “FirstCave2″. Simply try avoid adding decimals to the name. You could stick with the intended naming convention of “Cave
1-any number
“, but if not, try changing the “Cave” part to another similarly identifiable word.Then you can add on an extra line of else if statement in the
UpdateMap()
void UpdateMap(){ var savedScenes = SaveData.Instance.sceneNames; for(int i=0; i < maps.Length; i++){ if(savedScenes.Contains("Cave_"+ (i + 1))){ maps[i].SetActive(true); } else if(savedScenes.Contains("FirstCave_"+ (i + 1))){ maps[i].SetActive(true); } else{ maps[i].SetActive(false); } } }
I haven’t tested these, but with this knowledge, you should be able to create your own version of the map without much change.
April 25, 2024 at 2:18 am #14255::thanks alot. I just changed the names to cave_1,cave_2,cave_3… and now almost everything works fine.
but now for some reason the 14th room always appears, even if i hadn’t gone there
View post on imgur.com
also everything resets when i restart the game
April 25, 2024 at 2:24 am #14256::Likely what has happened is either, “Cave_14” is set active in your scene instead of inactive, or there is already a save file stating that you’ve been to “Cave_14”. So just delete the saved maps’ sceneNames file.
As for the maps not reloading on start, you just need an
Awake()
orStart()
that activates the updatemap method.April 25, 2024 at 3:52 am #14257::Cave_14 is set to inactive. What did you mean by “delete the saved maps’ sceneNames file” ?
April 25, 2024 at 1:05 pm #14258::In MapManager.cs
UpdateMap()
, thesavedScenes
are taken from the SaveData.cs HashSet calledsceneNames
. Try clearing the saved HashSet by following this: https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.clear?view=net-8.0April 25, 2024 at 2:31 pm #14259::I did this to the MapManager.cs and the map doesnt appear at all
<code>void UpdateMap(){ var savedScenes = SaveData.Instance.sceneNames; SaveData.Instance.sceneNames.Clear(); for(int i=0;i<maps.Length;i++){ if(savedScenes.Contains("Cave"+(i+1))){ maps[i].SetActive(true); } else{ maps[i].SetActive(false); } } }</code>
And then i removed the
SaveData.Instance.sceneNames.Clear();
line and still all of the map segments remain invisibleApril 25, 2024 at 2:36 pm #14260::Try saving scenes and opening maps again, now that you removed the
sceneNames.Clear()
function.Again, if you know how the code works, what we are doing is using the
Clear()
function once to reset the state of your map, you can remove it for future attempts, but to reset your map progress, useClear()
. With the code now removed, your Map should work normally through it’s intended use of saving scenes to open map.April 25, 2024 at 3:05 pm #14261::ok i figured it out. cave 14 was visible because it was the scene open in the editor. when i switch to the scene Cave_1, the cave_1 map segment is visible. if i start from the main menu everything works fine.
The only problem now is resting at a checkpoint. i have to mash F multiple times get the message “Rested in checkpoint”. I sometimes have to jump around while pressing F to get the message.
View post on imgur.com
View post on imgur.com
I also have to rest twice to update the map. how do i fix that?
View post on imgur.com
April 25, 2024 at 3:16 pm #14262April 25, 2024 at 4:44 pm #14266 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: