Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by valentin56610 · Feb 15, 2019 at 05:51 PM · builddestroydestroy object

[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

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xxmariofer · Feb 15, 2019 at 10:08 PM 0
Share

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?

avatar image valentin56610 xxmariofer · Feb 15, 2019 at 10:29 PM 0
Share

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 :)

avatar image xxmariofer valentin56610 · Feb 15, 2019 at 10:55 PM 0
Share

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?

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

113 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges