• 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
-1
Question by m4s4m0r1 · Jul 04, 2012 at 06:39 AM · gameobject

Remember Destroyed GameObject Position

hai i`m yusuf, i just want to know how to knowing and remembering Destroyed GameObject Position ? what script should i make?

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 AlucardJay · Nov 09, 2012 at 05:17 AM 0
Share

Hello. If an answer helped, could you please mark it as accepted. Thanks.

On the left-hand-side of the Answer box , there are the following icons :

 Thumb Up
 Number (of votes)
 Thumb Down 
 A Tick/Check $$anonymous$$ark

If an answer worked for you, click on the 'Tick/Check mark', the answer should now be highlighted in green and marked as accepted.

avatar image m4s4m0r1 · Nov 14, 2012 at 12:23 AM 0
Share

Ok, thank you for re$$anonymous$$d me... i`ll do it

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by AlucardJay · Jul 04, 2012 at 06:51 AM

Assign a variable to store the transform.position of the gameObject, then just before destroying update that var. e.g. (this is an example, not fully working code) :

   var destroyingObj : GameObject; // or the reference to your gameObject being destroyed
 
   var destroyedObjectPosition : Vector3; // variable to store position

   // In the function

   destroyedObjectPosition = destroyingObj.transform.position; // update var with object's position before destroying
   Destroy ( destroyingObj ); // object is destroyed
Comment
Add comment · Show 4 · 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 m4s4m0r1 · Jul 04, 2012 at 07:34 AM 0
Share

i have one more question. If i set speed and altitude GUIText in my script, then my GameObject is Destroy, How to set my speed and altitude GUIText to 0 if my GameObject is Destroy? sorry for my English

avatar image AlucardJay · Jul 04, 2012 at 07:43 AM 0
Share

change those variables at the same time as assigning the position, all before destroying the object. (assign speed = 0, assign altitude = 0, assign position = obj.transform.position, Destroy object)

avatar image m4s4m0r1 · Jul 04, 2012 at 02:47 PM 0
Share

Sorry its failed... its say "the Rigidbody is destroy but you still try accessing" what should i do? i want to make the rotation too...

avatar image AlucardJay · Jul 04, 2012 at 02:56 PM 0
Share

if you are calling a script that is a part of the gameObject being destroyed, then yes you'll get that error. The script doesn't exist anymore. You have to store the values somewhere else. It is hard to guess what you are trying to do without any script in the question. So my suggestion is the same :

 var destroyingObj : GameObject; // or the reference to your gameObject being destroyed

 var destroyedObjectPosition : Vector3; // variables to store position etc
 var destroyedObjectRotation : Quaternion;
 var destroyedObjectSpeed : float;
 var destroyedObjectAltitude : float;

 // In the function

 destroyedObjectPosition = destroyingObj.transform.position; // update vars with object's position etc before destroying
 destroyedObjectRotation = destroyingObj.transform.rotation;
 destroyedObjectSpeed = [depends on how speed is calculated, and where it is stored];
 destroyedObjectAltitude = destroyingObj.transform.position.y;

 Destroy ( destroyingObj ); // object is destroyed
avatar image
1
Wiki

Answer by Linus · Jul 04, 2012 at 06:54 AM

Something to get you started:

 var rememberMe : GameObject;
 var rememberMeLocation : Vector3;
 
 function Start(){
  rememberMe = GameObject.Find('nameofobject');
 }
 
 // Place right before the object is destroyed
 rememberMeLocation = Vector3(rememberMe.transform.position.x,rememberMe.transform.position.y,rememberMe.transform.position.z);
Comment
Add comment · Show 5 · 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 AlucardJay · Jul 04, 2012 at 06:55 AM 0
Share

?

 remember$$anonymous$$eLocation = remember$$anonymous$$e.transform.position;

not much different from my answer, also the gameObject to be destroyed could be an instantiated object, so GameObject.Find is not always suitable as a generic example

avatar image m4s4m0r1 · Jul 04, 2012 at 07:19 AM 0
Share

Ok I`ll try. Thanks

avatar image Linus · Jul 04, 2012 at 07:20 AM 1
Share

I did answer first :) $$anonymous$$y answers are moderated since I just signed up. $$anonymous$$arma is 1. Lucky question asker, he gets to alternatives. Yours require to assign in the inspector.

avatar image AlucardJay · Jul 04, 2012 at 07:26 AM 0
Share

np. Actually I was just declaring the gameObject variable. It can be assigned in the inspector, or in the script. $$anonymous$$y main point was the breakdown of your remember$$anonymous$$eLocation variable assigning could seem confusing, but does show the elements in the .position

no worries. like you said, more knowledge to the asker. And $$anonymous$$nowledge is Power !

=]

avatar image m4s4m0r1 · Jul 04, 2012 at 07:31 AM 0
Share

i have one more question. If i set speed and altitude GUIText in my script, then my GameObject is Destroy, How to set my speed and altitude GUIText to 0 if my GameObject is Destroy? sorry for my English

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Scripts wont work if deactivated then activated? 0 Answers

getting .Transform from instanntiated object 2 Answers

How to remove objects from a list ? 3 Answers

In Inspector gameobject check is not visible 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