- Home /
Game not working when I save, exit out of unity, then come back in.
So I've attached my code in screenshots.
Pretty simple code. The obtaining of GameObjects through "FindGameObjectWithTag" in the start method is done just to get some empty game objects that are located in the location that I want certain projectiles to spawn at.
The booleans are true when I want them to be. I ran a debug.log of them and they check out.
The problem is that when I initially open up unity, this script won't be working. So I remove the script from the game object it's assigned to in the hierarchy, attach the script again, reassign all the public game objects with some prefabs, and voila, the script works how I want it to. I'll then save the scene and all the scripts, exit out of unity, open it back up, and it stops working.
For the life of me I can't figure out how to fix this, and it's quite annoying to go through the process of fixing it in the way I described above every time I want to work on the game.
Any help will be appreciated.
Are you saving the scene AND the project? Ctrl-s only save changes to the scene and changes to stuff like prefabs requires you to actually do file => save project.
Answer by Bunny83 · Jan 23, 2016 at 03:45 AM
"this script won't be working" is't a helpful description of the problem. You said you checked with Debug.Logs. What have you actually checked? If Unity enters one of the if statements and calls the instantiate method it should create that instance.
Removing and readding the script might indicate a race condition between two of your scripts. So the order in which they are executed might be relevant. This script alone certainly isn't the problem. This script relies on Player.alive
and shootDelay.canShoot
. Those are most likely controlled by other scripts. If those scripts also react to Key down / up events of the same keys it depends on which script actually runs first.
We don't know how your other scripts look like. You have to debug them since you should know how they work. You might want to check your logic and maybe manually set the execution order of your scripts to ensure a certain order.
Sorry, I will try to be more descriptive next time I ask a question.
But you were right. I had a code in another script that was turning shootDelay.canShoot false before the prefab could instantiate.
Thanks for your help!
Your answer
Follow this Question
Related Questions
How to Use Object Pooling? Is my Script Wrong? 0 Answers
Unity Crashes When Spawning Prefab 2 Answers
Ingame prefab saving and manipulation 0 Answers
Projectile not launching from correct place - rotation or positioning issue? 0 Answers
Make a object spawn 1 Answer