Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 GhostDre · Mar 12, 2015 at 02:42 PM · gameobjectdestroymissing

Help, Missing Object

Hi everyone, I've been stuck on this part for a while and I don't know why, but I'm trying to clone my collect GameObject when isCollect is true. Then when isCollect is false, it should destroy the clone, but it's not doing that, its destroying the entire GameObject I think, and then when I take a look in the inspector it says Missing Object. I look through so many forms and questions and answers about this and I seem to have no luck. Any suggestions??

 if (isCollect) {
 
             if (!collectorObject) {
                 collectorPos = player.transform.position;
                 collectClone = Instantiate (collect, collectorPos, transform.rotation) as GameObject; 
                 collectorObject = true;        
             }
                         superCollectTimer += Time.deltaTime;
                         if (superCollectTimer < 5) {
                 
                                 
                 
                                         Debug.Log ("Collecting");
                                 
                         } else {
                 
                                 if (superCollectTimer >= 4.5f) {
                                         superCollectTimer = 0;
                                         isCollect = false;
                                         collectorTexture.enabled = false;
                                         energy -= 3;
                                         
                                 }
                         }
                 }
 
                 if (isCollect == false) {
             Destroy(collectClone);
                 }
Comment
Add comment · Show 7
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 AlwaysSunny · Mar 12, 2015 at 04:10 AM 0
Share

I don't detect a glaring issue, but all these conditionals look a wee bit messy. It looks like a case for a simple state machine or at least some coroutines to clean things up.

What says "missing object" - does it only say this after this code executes? Are you ever writing to or changing the variable which holds your prefab? This is generally unwise unless you know exactly what you're doing.

avatar image GhostDre · Mar 12, 2015 at 04:14 AM 0
Share

Yea sorry about that I have conditions functioning with other things. But it says missing object with the collectClone after its been excuted. And nope, I'm not changing the variable.

avatar image AlwaysSunny · Mar 12, 2015 at 05:09 AM 0
Share

$$anonymous$$y thought is that isCollect is being set to false immediately before execution returns to the line which destroys collectClone if it's false.

avatar image GhostDre · Mar 12, 2015 at 05:15 AM 0
Share

Yes isCollect starts off as being set to false, but once a certain score is obtained it is set to true. Once it is set to true the collectClone object appears. Then when the timer runs out ((superCollectTimer >= 4.5f)) isCollect is set to false and the collectClone should be destroyed. hopefully that makes since. Do you think that's the problem? And if so how do you think I can fix it?

avatar image GhostDre · Mar 12, 2015 at 05:42 PM 0
Share

Any other suggestions from anyone, Im can't seem to figure out whats wrong.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by games4ever · Mar 12, 2015 at 07:59 PM

Try this...

void Awake() {

 collectClone = null;

}

void Update() {

if (isCollect) {

   if (collectClone == null)
   {
      collectorPos = player.transform.position;
      collectClone = Instantiate (collect, collectorPos, transform.rotation) as GameObject;    
   }
   else
   {
      superCollectTimer += Time.deltaTime;
      if (superCollectTimer < 5)
      {
         Debug.Log ("Collecting");
      }
      else
      {
         Destroy(collectClone);
         collectClone = null;
         superCollectTimer = 0;
         isCollect = false;
         collectorTexture.enabled = false;
         energy -= 3;
      }
   }

} }

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 GhostDre · Mar 12, 2015 at 08:13 PM 0
Share

I was looking at referencing nulls, I didnt know how to implement it in my script but I will try this soon.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

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

missing gameobject ≠ Null? 1 Answer

Can't copy Gameobject into array, only refer to an existing one. 1 Answer

Need to manually destroy GameObject? 1 Answer

Particle system not destroying. 3 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