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 /
  • Help Room /
avatar image
0
Question by sniper02311 · Jan 15, 2019 at 09:51 AM · variablesclonedestroy object

[SOLVED]Deletion of instantiated clones not in order

There is a similar question I did read through, but my situation may differ a little (not to mention I believe it was in java code and I am using c#). I am new to Unity (1 week in) and I am creating clones from a prefab correctly in the game using a Canvas button routing to a script in the empty game object for instantiation. So, I create them, and they work as individual gameobjects, correctly taking the instance codes etc from the prefab with one issue upon deletion.

THe issue: The clones delete in order, even when I point to accessible script variables for deletion.

I have both creation and deletion classes in one script so I don't have to access too much external object information. I know that with "Find" (appears to be any Find function), that they do in fact delete (and detect) in order of Instantiation. I understand that, but is there a way to delete out of order? I have drag and drop coding so the object is under the mouse when I execute the class code for deletion, but it still deletes the first one, and then nothing can delete after because it errors with the gameobject is missing (which I debugged and verified using createdObjects variables to show each one created in order).

My creation code:

  public void CreateObj()
         {
             if (prefabCube != null)
             {
                 Vector3 position = new Vector3((minX + maxX)/2, (minY + maxY)/2, -14);
     
                 //create the object
                 prefabCubeClone = Instantiate(prefabCube, position, Quaternion.identity) as GameObject;
                 createdObjects.Add(prefabCubeClone);
             }
         }


Under that, my deletion code:

  public void DeleteOjb()
         {
             {
                 FindObjectsOfType<GameObject>(); //not necessary at the moment
                 GameObject.FindGameObjectsWithTag("prefabCube"); //not necessary at the moment
                 if (prefabCubeClone.GetComponent<DragDrop>().isActive == 1)
                 {
                     GameObject newClone = prefabCubeClone;
               
                 Debug.Log("WORKED");
                 Destroy(newClone);
     
                 }
             }
         }


So, I point to the clone(s) by name(i believe as a group Im not sure yet), then a script within them, and then a variable(isActive) in the script. isActive I have verified only can == 1 when the color changes upon drag and drop, and I did check that they change this variable indepenent also, so Im confused why when I say if isActive ==1 it does not understand the clone that actually has isActive==1 as the one I want to delete.

It appears that as long as I have isActive ==1 on ANY of them, it will still delete the first instance. I have heard of ray casting, and I tried that will no luck yet. I have also read a lot about colliders and With the executing code inside a Canvas button as an Event trigger (to outsource the execution), I do not know if that is the issue because it still works, just in order.

Thank you if you can help. I have been working on this part of the script for 2 days (12 hours average) testing different Unity tutorial and manual information but I cannot seem to get it right. I can delete a clone right now, and all scripting is working great other than needing to delete the right clone :P. I am unsure, other than instance variables (which I tried last today), how to reference them outside the order they instantiate for taking action in game.

Thank you and Bless you all!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sniper02311 · Jan 17, 2019 at 04:01 PM

[SOLVED] I figured it out.

What I did was take advantage of ray tracing at the axis the active camera was facing within 90 degrees either side and set the ray distance long enough to catch anything rendered in the viewpoint at a comfortable zoom factor. I debugged it to print the object name to make sure it found the right object and it works great. I now also use ray casting for collision detection without the need for mesh or rigidbody's since I am only using a custom editor scene for this part. Ill post details if anyone has the same issue.

Comment
Add comment · 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

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

165 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 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

destory object not variable 2 Answers

Destroy specific clone 3 Answers

[SOLVED] How to destroy a cloned object if it object colliding with another cloned object ? 1 Answer

Destroy function destroying only one object and not destroying his clones 0 Answers

How can you load next the level after you destroy the last clone c# 1 Answer


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