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 ExcitedMormon · Aug 04, 2014 at 04:22 AM · c#spawn

Why Does My GameObject Not Spawn Anymore?

Why does my gameobject not spawn if I don't grab it? The other gameobjects spawn just fine even after not grabbing it, but not this certain one. The gameobjects are all constantly spawning, except the one that doesn't respawn after not grabbing it because it's supposed to spawn only after I collect 10 of a different gameobject(I hope you understood that). So what could be the problem? Here's my GameObject script(this script spawns both the gameobjects I need to collect and the one that doesn't respawn): http://pastebin.com/RuU9UrDj

Now I have a pretty good feeling that it's defiantly the script that I posted that's the problem. I tested it with a different spawn script and the gameobject respawn/kept spawning even after not grabbing it. I know this is pretty a vague explanation and question, so I'm sorry. Anyways I hope someone can help me see what's the problem here.

Comment
Add comment · Show 9
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 Noob_Vulcan · Aug 04, 2014 at 06:11 AM 0
Share

does the code even get into Instantiate(bigcoin, bigspawn.transform.position, Quaternion.identity); ; I hope this the GameObject THat doesnt spawn?

avatar image ExcitedMormon · Aug 04, 2014 at 06:42 AM 0
Share

Yeah the bigcoin is the one that stops spawning. To answer your first question, yes the code does get into that line, but only until the destroyer destroys it. After the gameobject gets destroyed, it stops working. The debugs no longer appear after it destroys the bigcoin gameobject.

So the Debug.Log("I Love You"); appears when I collect 10 of a different gameobject, the Debug.Log("You Love $$anonymous$$e"); appears when the bigcoin power up spawns, and on the destroyer script the Debug.Log("Z"); appears when it destroys the bigcoin. After "Z" appears none of the debugs appear again. Only if I don't let bigcoin get destroyed will it work, so what the heck?

avatar image ExcitedMormon · Aug 05, 2014 at 09:14 PM 0
Share

Bump. This is either a bug or my code is missing something. This could add some challenge to my game though.

avatar image Kiwasi · Aug 05, 2014 at 09:19 PM 0
Share

I feel we have something in common here, will have a look tonight and see what I can find.

Or you could post the problem scripts here and I could look sooner.

avatar image ExcitedMormon · Aug 05, 2014 at 09:40 PM 0
Share

Hmm, problem scripts? Do you mean the ones that don't work correctly(not appearing on the console)? Not sure what you mean here, but the only one that doesn't seem to work correctly is the GameObject/Spawn script that's supposed to spawn the bigcoin gameobject, but it doesn't after it get's destroyed. Here it is: http://pastebin.com/RuU9UrDj

To sum it up, the script makes you collect 10 of a different gameobject tagged as Item1, and after you collect 10, it spawns in the gameobject tagged as Coin(which is the one that doesn't spawn again after getting destroyed). Hope you understand.

Show more comments

2 Replies

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

Answer by meat5000 · Aug 05, 2014 at 09:30 PM

At a glance, you need to pick up a "Coin" before spawned = false; If you havent done this the instantiation is not invoked. Not sure if Im just describing your intended behaviour here.

But this:

 && timer == 0

Could be a problem too. How about:

 && timer <= 0.0f


Comment
Add comment · Show 17 · 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 ExcitedMormon · Aug 05, 2014 at 09:54 PM 0
Share

Interesting, I didn't notice that those could be a problem. I'll see if that works. Thanks meat.

avatar image meat5000 ♦ · Aug 05, 2014 at 09:58 PM 0
Share

No problem. The trouble with timer == 0 is that trying to evaluate a float as smack on 0 is very unlikely. So as its a float, evaluate it as a float, evaluate it equal or below and stick the f on the end so it doesnt think its a double or something.

avatar image ExcitedMormon · Aug 05, 2014 at 10:06 PM 0
Share

I never knew that, thanks for the information. So I tried it, it doesn't seem to affect the spawning. The gameobject tagged as coin still doesn't spawn after it get's destroyed. So it seems like that wasn't the problem, so maybe it's the spawned = false?

avatar image ExcitedMormon · Aug 05, 2014 at 10:14 PM 0
Share

I think if that really is the problem, then there are a couple of ways I might be able to fix it. I can post them but first I'll try them out, then tell you my results.

By the way, the spawned = false is there because without it the Coin won't respawn even if I pick it up. With it, it makes the coin respawn after I collect 10 more "Item1", and it keeps doing it until it get's destroyed by the destroyer that's following me off screen behind me. That's when it doesn't respawn.

avatar image meat5000 ♦ · Aug 05, 2014 at 10:31 PM 0
Share

destroyed by the destroyer that's following me off screen behind me. That's when it doesn't respawn.

So destroyed out of sequence?

Show more comments
avatar image
0

Answer by Foose · Aug 08, 2014 at 06:12 AM

Your problem is, that you destroy the parent game object and with it your whole script. So after u have destroyed it, the script doesnt exist anymore. You should just make a parent gameobject with the destroyer script and let the to be destroyed items spawn as children into it. Than call the destroy function for children and not for the parent. Should solve your problem

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 ExcitedMormon · Aug 08, 2014 at 08:31 AM 0
Share

Hmm this could work, problem is, is that now that I've looked into it more, it seems the actual problem is with the script spawning the gameobject and not the destroy script. Even if it doesn't get destroyed, it still won't re-spawn after I collect 10 "Item1" tagged gameobjects. By the way, did you test it? Your solution? I'm just curious(seriously I am).

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Selecting and deselecting not working 0 Answers

Error whit c# code 'UnityEngine.Transform.position' because it is not a variable. 1 Answer

Make player not be seen by AI, when player in foilage and shadows. 1 Answer

Collider doesn't transfer to function 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