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 Dhannanjai · Jun 09, 2017 at 06:04 AM · errorinstantiateprefabdestroymaze

Instantiated gameObject(here, wall) destroyed, but when checked for existence, shows that it exists, how?

Hello there! I have been making a game on Mazes. For this I have to destroy a few walls from a grid that I created.Also, I am trying to solve the Maze through Dijkstra Algorithm. For this, I have to check whether the cell(unit of Grid) has wall or not. Unfortunately, the statement when checked for "null" does not compute to true.

In Maze Generator Script

Here the wall are instantiated using :
tempWall = Instantiate(wall, newPos, Quaternion.identity) as GameObject;

and are later destroyed using :
Destroy(cells[_currentCellNumber].up);

Cells Script(not derived from MonoBehaviour)

  [System.Serializable]
    public class Cells{
     public bool visited = false;
     public GameObject up; //    1
     public GameObject down;//   2
     public GameObject left;//   3
     public GameObject right;//  4
     }`  


Checking in Dijkstra Solve Maze

if (cells[currentCellNumber].left.gameObject == null

Unfortunately, the block of statement for 'If' is never executed. But if the code is changed to: if (cells[currentCellNumber].left.gameObject != null)

The statement does get executed,but for all the wall, also which does not exist. Pleaes help me, thanks in advance!

Comment
Add comment · Show 2
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 SohailBukhari · Jun 09, 2017 at 06:11 AM 0
Share

i think you are destroying Destroy(cells[_currentCellNumber].up); up and you are checking left whether it exist or not? em i right? you have to check

 if (cells[currentCellNumber].up.gameObject == null)

ins$$anonymous$$d off if (cells[currentCellNumber].left.gameObject == null No need to check if (cells[currentCellNumber].up.gameObject == null) you can simply check if (cells[currentCellNumber].up.gameObject)

avatar image Dhannanjai SohailBukhari · Jun 10, 2017 at 09:17 AM 0
Share

I have tried that already. I even tried by checking for mesh renderer(which does not show up on the game scene) and also for collider,but it did not work.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Garazbolg · Jun 09, 2017 at 04:26 PM

I'm not sure but you it might have to do with your Garbage Collector : When you destroy your wall also set your variable to null, like this :

 Destroy(cells[_currentCellNumber].up);
 cells[_currentCellNumber].up = null;

And instead of checking the gameObject like you do (in a redundant way), do :

 if (cells[currentCellNumber].left== null)
Comment
Add comment · Show 1 · Share
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 Dhannanjai · Jun 10, 2017 at 11:26 AM 0
Share

Hey, it worked.Thanks!!!

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

6 People are following this question.

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

Related Questions

Instantiating prefabs: "The object of type GameObject has been destroyed". 1 Answer

updateMassFromShapes error 2 Answers

Deleting a GameObject 2 Answers

Cannot destroy child object in prefab- Error 1 Answer

problem whit Instantiate Prefabs position. 0 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