Script is suddenly unable to find a GameObject in the scene - unity3d

Last night I was working on my game, and everything seemed to be working perfectly. I added a sprite to my Assets/Sprites folder, then my laptop died. When I plugged it in and turned it back on, the GameObject.Find("Weapon Wheel") line in my PlayerControls script was no longer able to find the weapon wheel object. To my knowledge, no changes to the scene or any scripts were made.
Even stranger, my CommandPattern script also has GameObject.Find("Weapon Wheel"), and is able to find it perfectly fine.
Has anyone experienced the Find function suddenly not working, and if so, found a solution for it?
EDIT: Deleting the player prefab then replacing it with a new one fixed the issue, but I still have no idea why this happened in the first place.

I dunno how ur game is architectured and a direct solution but you can try to create a Gameobject variable in the Playercontrol class and then drag the weapon wheel in the field in the unity overlay

Related

Problem with loading next level in Unity 3D

I have a 3D game, and I added a trigger that loads the next level with a small animation when the player goes through it. It all works fine in Unity editor, but when I build the game it does not load the next level, neither it shows the animation. Any ideas what could be wrong? Thank you!
Hard to say without more detail, but in general it boils down to one of two things. Either the trigger is not firing, or there's a problem with the script.
Try attaching something else to the trigger, maybe something that will enable a disabled GameObject in a position that would be visible when you're hitting this trigger. If that doesn't show up, that tells you the problem is with the trigger.
Otherwise, you have a script issue. The most likely cause is that you're trying to load a scene that isn't listed in the project's Build Settings. Double-check that the scene for the level you're loading is in there, or it won't get built into the project. If the call to LoadScene/LoadSceneAsync is in your script before the call that is running the animation, then if it errors out due to the scene not being available, it would never reach the point where it plays the animation, which would explain what you're seeing.

Floppy Disk icon Middle of my screen when game is running

I'm a beginner in unity and programming, I was following a video for making a Flappy Bird game. Everything works perfectly but when I run the game, I get a floppy disk icon middle of the screen and somehing called DontDestroyOnLoad starts working out of nowhere. I couldn't find or understand anything on google when I search for it. I'm posting the screenshots in case anybody wanna see it.
This icon and dontdestroyonload thing only appears when game is being run:
There's a little button in the type right of your scene and game view called "Gizmos", un-toggle that button, should fix your issue.
Also don't worry, Gizmos can only be seen in the Unity Editor for level editing and debugging purposes --> if you were to build the game, for instance on IOS, they would disappear.
(if this doesn't fix your issue, then I would just create a new scene and copy your gameobjects over one-by-one)
I see someone responded about the main part of a problem, but I'll clarify about dontdestroyonload
Don't destroy on load is collection of objects that won't be destroyed when new scene will be loaded, usually objects there come from running them through DontDestroyOnLoad method somewhere in a script, however I noticed that some time ago Unity creators started to put there some stuff related to built-in tools (like debug)

Unity: suddenly some gameobjects stopped beeing shown

I'm a Computer Science
Engineering student. I'm currently working on a Uni project using Unity to build a 2D game. Until this morning everything was fine, but suddenly after some work on a UI Manager Script in my menu scene (Scene 0) when I tried to play the game some gameobjects (apparently random) stopped to be visualized on Scene View and on Game View in the Level scene (Scene 1).
I can see all gameobjects fine on camera preview and they all are active in the hierarchy, even all colliders are working.
I tried to look on the web, but I can't find any solution or any similar case...
I don't really have any ideas, I'll be really glad if someone can help me. Thanks.
Check the Material variable on the Sprite Renderer component and make sure it's set to "Sprites-Default". In my case, the material for the hidden objects had somehow changed to "None" while I was working on a little postprocessing effect.
Edit: Here's how the material changed. Adding a SpriteGlow script from a package which works with postprocessing had first turned the objects' SpriteRenderer material from the original "Sprites-Default" to "Sprite/Outline". Upon removing the SpriteGlow script component from the object, the material became "None" rather than defaulting back to "Sprites-Default" and that was when I stopped seeing the objects even though they were present in the scene. This is most likely your problem too since you said every other thing like collision works and the objects are definitely present in the scene.

Gameobject sprite missing at runtime when animator is enabled

I've identified a problem with one of my 2d platform gameobjects with a animator component attached to it.
The platforms sprite goes missing at runtime and this is directly caused by the animator itself, which before wasn't a problem. when I disable the animator and run the game the sprite doesn't go "missing", but as soon as I enable it, it's missing again.
This is probably happening because I started the project in unity 2019b and switched to 2018.4.12 because I was getting weird CURL errors that prevented me from building for Android. The affected prefab(platform) functions as it should other then the fact that the sprite goes missing at runtime and nothing about the project has changed. Code works perfectly as it did when there were no issues.
I just installed unity 2019.2.13 hoping this would solve it but no change. Tried re-importing the asset but nothing. This isn't a collision issue. The 'z' axis is not modified at runtime. and its definitely not a code issue because as stated before the functionality isn't affected, its just the sprite going missing. I'm out of ideas now and exhausted online resources. Can anyone help in any way. Thanks in advance.
simple fix. i just created a new prefab and re-created the animations... Annoying but it worked

GameObject.FindGameObjectWithTag returning (clone)?

im having this problem and its when i use
GameObject.FindGameObjectWithTag("red");
it started when i added an animator component to the gameObject
its returning
red(Clone)
when the game object is in the heirarchy as the only gameobject with the tag "red"
it only happened after i added the animator component and when i exited from unity and restarted unity the problem went away, the error i was getting was
MissingComponentException: There is no 'Rigidbody2D' attached to the "red(Clone)" game object, but a script is trying to access it.
there is a red in the scene not a red(clone) but i seen in the inspector when i used GameObject.FindGameObjectWithTag("red") it found red(Clone) but there is no red(Clone) just red in the scene, it happened after i added a animator component and stopped when i rebooted Unity, its gota be a bug, just thought id check here
edit
just how i said that there was a red in the scene there was a RigidBody2d attached to it too, just no existence of a red(Clone), thank you for your time
This seems to be a long running bug in unity, dating all the way back to 4.3. Which hopefully will be fixed in unity 5
It seems the animator window causes a clone for some reason, which is not removable.
There are only 2 ways to bypass this problem as known to date
If you did not save the scene yet, close the animator window, close unity and restart unity. This should rid you of the object.
in case you already saved the scene
Use another tag instead, so instead of red use Red.
General advice, try to avoid using the FindGameObjectWithTag as long as the bug is running. As stability is not guaranteed.
Some other less optimal ways to deal with this problem:
Find and destroy the clones before using it:
GameObject[] remaining = GameObject.FindGameObjectsWithTag(Tags.player);
foreach (GameObject clone in remaining) {
if(clone.name == "Player_Aleysha(Clone)"){
GameObject.Destroy(clone);
}