- Home /
[SOLVED] Object don't get destroyed when game is built
Hi :)
I am making an RPG, and once I killed an enemy I want it do be destroyed. So it works fine in the editor, but once I build the game and run it, once i exit the game and re open it, monsters that i killed are still here. At the end of the fight i set the value of the monster I killed at 1 so my monsterhandler (also saves this in my .json file) destroys the right monster :
// destroy a precise object in the game based on its name
public void KillEnemy()
{
if (LoadingBattle.enemyPersonnalName == "Goblin1")
{
MonsterHandler.goblin1 = 1;
}
else if (LoadingBattle.enemyPersonnalName == "Troll1")
{
MonsterHandler.troll1 = 1;
}
}
Then my monster handler does his job :
using System;
using UnityEngine;
[Serializable]
public class MonsterHandler : MonoBehaviour
{
public static int goblin1;
public GameObject Goblin1;
public static int troll1;
public GameObject Troll1;
public void Update()
{
if(goblin1 == 1)
{
Destroy(Goblin1);
}
if (troll1 == 1)
{
Destroy(Troll1);
}
}
}
The json file saves all the data, its works too, I checked, like it sets the value to what they should be but the monsters are there ! Thought they shouldnt because the update function says they should day, I'm a bit confused about this strange behaviour ... the values in the .json file are correct, but for some reason my game ignores them :( Just like if the update function wasnt working idk
EDIT : Ok i solved it, as i copy/pasted the path to make several save file, I forgot to change the path of it, and by reading it again in details I found out that my monsterfile had the path of the chest xD solved! now it works
hello, it is logging any error? maybe is not accessing the json? is it build to android? can you debug.log goblin1 and troll1 value in the update and check what is giving?
hey :) no absolutely no error, as I said, the values are changed as supposed to, like the save and loading works fine. once i killed the goblin it disappears from the map then sets its value to 1 so my json file when it loads everything. What doesnt work though is when i quit and re open the game and load all my data then both monsters are still here. even with changed values.. so .. I dont understand :(
EDIT : I debug log and it says 0. So it must be not working at some point. I'll check my load again though it works ... I'll keep you updated :)
it is not giving you any error or is the game not crashing? cause something like not being able to read the json will not stop the game but will give a debug.log error. it is the game built to android? iwhere is the json located?
Your answer
![](https://koobas.hobune.stream/wayback/20220612191756im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
how to destroy enemy 1 Answer
Prevent destruction of an object's child 1 Answer
How could i make it so that my bullets destroy after x amount of seconds? 2 Answers
Set destroy order 2 Answers