- Home /
level doesn't work after reloading
Im having issues with a puzzle game i am working on. it functions similar to minesweeper. The numbers on the columns and rows indicate the amount of bombs and points there are. So when i load the scene from the Mainmenu scene the first time after starting the game in the editor, it works fine. Win or lose, it brings you back to the main menu, when you go to to retry the level, the following image happens On the second attempt, the text doesn't update to show the updated text for the bombs/points
[EDIT: 1/27] After testing, it looks to be the box colliders on the columns/rows aren't detecting collisions (bombs and points that get spawned) after the scene is reloaded,
I have tried using OnTriggerEnter and OnTriggerStay, i tried using Rigidbody/BoxCollider as well as Rigidbody2D/BoxCollider2D and none of those worked.
Are there any error messages when you reload the game?
$$anonymous$$y first thought is that some references are being lost, which should result in some errors.
@Larry-Dietz That's what is weird, no errors are co$$anonymous$$g up. i did originally use a static variable to keep track of info different objects had to pull from (ie: number of rows/column based on difficulty picked), but when i found out that static variables have only one global instance, i thought info could be left over after playing round one. I updated my code to remove the static variables and fix the references to them but still get the same issue.
Whats confusing me, is if the menu and the game are different scenes, then when you load the game scene from the menu scene, it should be a clean load weather it is the first time or the 30th time, I would expect.
How are you getting references to the text components? Are they public and being dragged into the script? Or are you finding the references in start?
If they are public and being dragged in the inspector, one your 2nd load, when it messes up, take a look in the inspector and see of the references are listed as missing.
Hey @Larry-Dietz Heres some info to clarify. Scenes: $$anonymous$$ain$$anonymous$$enu, Level1-3, Info$$anonymous$$enu, actions: -$$anonymous$$ain$$anonymous$$enu(works)>Level1(works)>$$anonymous$$ain$$anonymous$$enu(works)>Level1(doesn't work)
The column and row objects have an empty child object with a textmesh that gets its text field edited from the column/row script.
i should note that when level1 scene loads, a level manager object instantiates a 'spawner' that handles instantiating all of the columns, then rows, then the bomb/point object.
when i was looking over the inspector values, there didn't seem to be any missing, but i wont be able to double check until i get home from work later
Let me guees, are you using Awake() function? Then it will not work, use Start() or OnEnable() ins$$anonymous$$d.
I use Awake() to initialize colider size and center position, i use OnTriggerEnter to update the numbers shown on the row/column objects
So Awake() is proble, try OnEnable and let me know if it's working. OntriggerEnter is okay.
Answer by Hassan-Kanso · Jan 27, 2020 at 04:43 PM
is the main menu another scene or you're loading it in the same level scene? and what does the retry button actually do? I imagine it should just load the level scene
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Surface with hole and Raycast - Which collider 1 Answer
How Does OnTriggerEnter() Work? 0 Answers