Search Unity

Can't add component because it doesn't exist???

Discussion in 'Editor & General Support' started by FastCodingMonkey, Jun 14, 2014.

  1. FastCodingMonkey

    FastCodingMonkey

    Joined:
    Jun 14, 2014
    Posts:
    8
    This is the second time this has occurred; after the first time i re-installed unity and re-crated the scripts through copy and pasting so everything was back to normal, not to bothered though since i am just practicing with c# object programming., when opening the project after the 10th-ish time all of the scripts cannot be found by unity although they are all in the scripts folder in the assets folder, and all of the scripts names have the same name as their classes. At first I was able to access the scripts through double clicking on the script component in the inspector tab, but they said they could not be accessed or where missing. Thank you very much for your time.
    upload_2014-6-14_23-0-12.png
    upload_2014-6-14_22-59-2.png

    upload_2014-6-14_22-57-31.png
     
  2. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    What kind of file is the one called Hooking?
     
  3. FastCodingMonkey

    FastCodingMonkey

    Joined:
    Jun 14, 2014
    Posts:
    8
    i removed the .cs from the end of the file just to see if that was the issue
     
  4. FastCodingMonkey

    FastCodingMonkey

    Joined:
    Jun 14, 2014
    Posts:
    8
    i removed the .cs from the end of the file just to see if that was the issue, but no its just a plain text file.
     
  5. FastCodingMonkey

    FastCodingMonkey

    Joined:
    Jun 14, 2014
    Posts:
    8
    Btw i would like to add that the first screenshot is to prove that it does not give me the option to add an already existing script even with scripts placed in the assets/scripts folder.
    Not to be confused with me trying to make a new script and getting that error on the second screen shot,
    If you need more information to solve this issue just ask. again thank you for your time.
     
  6. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Did you save the PlayerMovement.cs file? I see from the MonoDevelop screenshot that you've got unsaved changes… sometimes people make the mistake of editing the code but forgetting to save the file, so from Unity's point of view the file still contains a class called 'NewBehaviourScript.'
     
  7. FastCodingMonkey

    FastCodingMonkey

    Joined:
    Jun 14, 2014
    Posts:
    8
    Yes i saved the file, but this happens to all of the scripts even the unchanged ones that previously worked.
     
  8. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Can you select PlayerMovement.cs in Unity and post a screenshot of what you see in the Inspector when that file is selected?
     
  9. FastCodingMonkey

    FastCodingMonkey

    Joined:
    Jun 14, 2014
    Posts:
    8
    it appears with the correct code if thats what you are looking for?
     
  10. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Yes that's what I wanted to check.

    Do you have any compile errors shown in the Console?
     
  11. FastCodingMonkey

    FastCodingMonkey

    Joined:
    Jun 14, 2014
    Posts:
    8
    upload_2014-6-15_23-39-57.png
    Ignore the second line (transform.Translate = Vector2.distance) i realised it is incorrect, but i just used this script as of one of the examples of the many other working ones
     

    Attached Files:

  12. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    Ah, be careful - from your screenshot there it looks like you might have warnings and errors in the Console turned off (the buttons in the toolbar at the top of the Console). Make sure they're turned on when looking for error messages…

    Note that the compile error may not need to be in the PlayerMovement script for it to interfere with your ability to use the script correctly. Any compile errors need to be fixed before code changes will be properly reported/usable in Unity.
     
  13. FastCodingMonkey

    FastCodingMonkey

    Joined:
    Jun 14, 2014
    Posts:
    8
    Thank you very much for your help, I have yet to solve the issue but I think I have found the location of the problem, which I will try and resolve at a later date since time is not currently available to me :/
     
  14. Jaqal

    Jaqal

    Joined:
    Jul 3, 2014
    Posts:
    288
    Anyone solve this issue. Im having the same problem. I can't use any of my scripts as it says none of them exist?
     
  15. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    You probably have a compile error.
     
    speedocreedo likes this.
  16. junebug12851

    junebug12851

    Joined:
    Aug 6, 2014
    Posts:
    2
    I was also having this issue except mine was caused by renaming the script in Unity, afterwards everything worked normally (Mono had no problem opening it, I could edit and save just fine, Unity had no problems showing it, everything was all there) the only issue I ran into was, despite that, Unity suddenly had no idea where the file was when I dragged and dropped it to a component thus giving this error despite the fact that Unity has no problem working with it at all in itself or Mono.

    The solution for me was to delete the file entirely from Unity and recreate it under the new name I had chosen when I renamed it earlier, then just paste in what was in the file from earlier. Now Unity's mysterious magical like amnesia is gone lol.

    If that helps anyone as my issue was similar but not exactly the same as the original poster
     
    aspcore, MarvanMohr and guitarxd like this.
  17. Meinders

    Meinders

    Joined:
    Aug 7, 2014
    Posts:
    1
    I am running into the same issue as the original poster described. At first I thought it was a matter of renaming the scripts, because that was when it happened the first time; however, I've had it happen a couple times since then when I'm certain no files had been renamed.

    I was concerned that I had changed my default editor over to Notepad++....is there any reason I should switch it back to MonoDevelop?

    This last time it occurred, I was making changes in a script...adding a public variable, but could not figure out why it wasn't appearing in the inspector. After staring at the script over and over, muttering, "it should work...", I finally rebooted my system. After the reboot, Unity told me all my files were missing, despite being able to open them and edit them. ????
     
  18. Jaqal

    Jaqal

    Joined:
    Jul 3, 2014
    Posts:
    288
    This is a pretty common bug (at least for me) and the only way I have found to fix it is remake the last script I was working on. Now whenever this happens I copy the last script I was working on delete it and paste it into a new script. So far this has fixed the problem every time.
     
    a. s. likes this.
  19. Noctys

    Noctys

    Joined:
    Aug 23, 2013
    Posts:
    37
    I experienced this same issue after renaming a script in the Project View. The issue is that renaming it in the Project View does not rename the class and Unity needs the name of the file to match the name of the class. To fix this I just had to rename the class to match the file name. Pain in the butt and I would call it a bug - but it's easier that deleting and recreating the file.
     
    kadkaz likes this.
  20. ahinbazly

    ahinbazly

    Joined:
    Sep 4, 2014
    Posts:
    1
    This problem happened to me also, when I have compilation errors in one of my scripts, so I couldn't attach any script to game objects.
    Just make sure there are no compilation errors in your scripts, the errors should be appeared in the console window.
     
  21. Toutjimbwa

    Toutjimbwa

    Joined:
    Feb 8, 2014
    Posts:
    1
    I had the same error and my solution was to fix the errors in -other files- (errors seen in the console). Then after that it worked fine.
     
  22. I14R10

    I14R10

    Joined:
    Sep 15, 2014
    Posts:
    43
    It happened to me is I had two scripts with same name. Also try to write it in JS instead C#.
     
  23. mix773

    mix773

    Joined:
    Oct 7, 2014
    Posts:
    3
    Gyes, I've solved this problem finally. The key is that the file name and the class name must match EXACTLY, including capital letters, spaces, etc.
     
    VoonyArvid likes this.
  24. akiel123

    akiel123

    Joined:
    Nov 18, 2013
    Posts:
    7
    I'm having the same problem (kinda).
    It happens when I close (and save) my project (The entire Unity program) and open it again. I installed unity 4, 4 days ago, on a Lenovo running Windows 7.
    All of my script names match the names in Monodevelop (I haven't changed them since relaunch, and it worked before relaunch). It includes all of my scripts, including the ones importent from default unity packages, souch as MouseControl, and even if I delete the asset and reimport it the problem persits. If I change the scripts in movodevelop, Unity registers the changes (can see them in the inspection folder and if I change the name in movodevelop it also changes in Unity), so it seems like it should work together.

    Anyone knows a solution?
     
  25. Peelark

    Peelark

    Joined:
    Nov 8, 2014
    Posts:
    2
    I think mix773 has this generally nailed.

    Problem : Created a new C# script and named it, noticed a typo and corrected it in Unity. Tried to drag it into a folder and it didn't work, flagging the "does not exist" error as above.
    Solution: Edited the script in mono (or notepad) to make the class exactly the same as the filename.

    Voilà!

    (I'm afraid this may not fix akiel123's issue though...)
     
  26. Sphelps

    Sphelps

    Joined:
    Jun 9, 2013
    Posts:
    243
    Any fix for this.
    I have this same problem 2 or 3 times now. I am pissed
     
  27. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Several "fixes" are mentioned in this thread:
    - Make sure there is no compilation error
    - Make sure the class name and the file name are identical
    - Make sure there is more than one script with the same name (except if you use namespaces)
     
  28. TheGamingBuddies

    TheGamingBuddies

    Joined:
    Oct 30, 2014
    Posts:
    2
    Can't add component 'Player' because it doesn't exist.
    Check to see if the file name and class name match.
    =======================================
    Thank you for further help and here is the code
    =======================================
    var PlayerState : float;

    var PlayerAnimSec : GameObject;
    var JumpingAnimationSec : GameObject;

    var PlayerMotor : CharacterMotor;
    var WalkingSpeed : float = 6;
    var AimingInSpeed : float = 2;
    var SprintingSpeed : float = 8;
    var PlayerBossController : CharacterController;
    var CharacterMag;
    var PlayerAimingInSpeed : float = 0.2;
    var Jumped : boolean;
    var ReloadingGun : boolean;
    var PlayerTopGun : GameObject;
    var AimingIn : boolean = false;
    var GunDown : boolean = false;


    function Update ()
    {

    PlayerStateController();
    PlayerAnims();
    CharacterMag = PlayerBossController.velocity.magnitude;
    ButtonClicker();
    }

    function ButtonClicker()
    {
    if (Input.GetButtonDown("Gun Down"))
    {
    if (GunDown == true)
    GunDown = false;

    else

    if (GunDown == false)
    GunDown = true;
    }
    }

    function ReloadController()
    {
    ReloadingGun = PlayerTopGun.GetComponent(GunScript).Reloading;
    }



    function PlayerStateController()
    {
    if ((Input.GetAxis("Vertical") !=0 || Input.GetAxis("Horizontal") !=0))
    {
    if (Input.GetButton("Sprint")&&!Input.GetButton("Fire2") && PlayerBossController.isGrounded)
    {
    PlayerState = 2;
    AimingIn = false;
    }

    else if (Input.GetButton("Fire2") && !Input.GetButton("Sprint"))
    {
    PlayerState = 3;
    AimingIn = true;
    }
    else
    {
    PlayerState = 1;
    AimingIn = false;
    }

    }
    else
    if (GunDown == true && !Input.GetButton("Fire2") && !Input.GetButton("Fire1"))
    {
    PlayerState = -1;
    }

    else
    if (!Input.GetButton("Fire2"))
    {
    PlayerState = 0;
    AimingIn = false;
    }

    else if (Input.GetButton("Fire2") && !Input.GetButton("Sprint") && ReloadingGun == false)
    {
    PlayerState = 3;
    AimingIn = true;
    }
    }




    function PlayerAnims()
    {
    if (Jumped && !PlayerBossController.isGrounded)
    {
    Jumped = false;
    JumpingAnimationSec.animation.Play("Jumpingliftoff Animation");
    }

    if (!Jumped && PlayerBossController.isGrounded)
    {
    Jumped = true;
    JumpingAnimationSec.animation.Play("Jumpingland Animation");
    }


    if (PlayerState == -1)
    {
    PlayerAnimSec.animation.CrossFade("Gun Down Idle Animation");
    }

    if (PlayerState == 0)
    {
    PlayerAnimSec.animation.CrossFade("Idle Animation");
    }

    else if (PlayerState == 1 && PlayerBossController.isGrounded)
    {
    PlayerAnimSec.animation["Walking Animation"].speed = CharacterMag/WalkingSpeed;
    PlayerAnimSec.animation.CrossFade("Walking Animation");

    PlayerMotor.movement.maxForwardSpeed = WalkingSpeed;
    PlayerMotor.movement.maxBackwardsSpeed = WalkingSpeed/2;
    PlayerMotor.movement.maxSidewaysSpeed = WalkingSpeed;
    }

    else if (PlayerState == 2 && PlayerBossController.isGrounded)
    {
    PlayerAnimSec.animation["Sprint Animation"].speed = CharacterMag/SprintingSpeed;
    PlayerAnimSec.animation.CrossFade("Sprint Animation");

    PlayerMotor.movement.maxForwardSpeed = SprintingSpeed;
    PlayerMotor.movement.maxBackwardsSpeed = SprintingSpeed/2;
    PlayerMotor.movement.maxSidewaysSpeed = SprintingSpeed;
    }

    else if (PlayerState == 3)
    {
    PlayerAnimSec.animation["Aiming In Idle Animation"].speed = 1+(CharacterMag/WalkingSpeed);
    PlayerAnimSec.animation.CrossFade("Aiming In Idle Animation",PlayerAimingInSpeed);

    PlayerMotor.movement.maxForwardSpeed = AimingInSpeed;
    PlayerMotor.movement.maxBackwardsSpeed = AimingInSpeed/2;
    PlayerMotor.movement.maxSidewaysSpeed = AimingInSpeed;
    }
    }
     
  29. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  30. Jimmiejam

    Jimmiejam

    Joined:
    Dec 19, 2014
    Posts:
    1
    Yeah I had exactly the same problem.

    I tried deleting the file and remaking it under the same name, checking that the class name and script name was the same, and that there weren't duplicates.

    So in the end I copied all the data, deleted the script, clicked on the object that I wanted it attached to, and created it through the add component, add new script (and then pasted it).

    Seems ok now but it's not showing me public variables tied to it through the gameobject atm... maybe there's a bigger issue but worth a tell.
     
  31. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    There is usually a bigger issue, but caused by the people who are having that issue.
     
  32. Stevepunk

    Stevepunk

    Joined:
    Oct 20, 2013
    Posts:
    205
    I had this problem. The issue was that the script name and class name didn't match.

    Usually Unity names the class name to whatever the script name is, but Unity lagged and I misclicked and had to rename the script after creation (thus it no longer matched).

    When I renamed the class name to match (with copy/paste to be sure), it worked without issue.
     
    Ony likes this.
  33. einzweidrei

    einzweidrei

    Joined:
    Jan 19, 2015
    Posts:
    2
    Solved this issue by doing the same function an other way around.
    Select desired object, the one you want to attach scripts on and click Component on the upper most navigation menu than select Add... than on the Component dialog select New Script than enter exact name of the script and choose C# on the language dropdown.
    The previous option should be working but ...
    ;)
     
  34. HauntedHotPocket

    HauntedHotPocket

    Joined:
    Jul 7, 2013
    Posts:
    1
    I found this happening when I incorrectly declared a class I was extending from another class. Ex:

    Level3Script.js
    class Level3 extends LevelScript //wrong
    VS
    class Level3Script extends LevelScript //correct
     
  35. PSpiroz

    PSpiroz

    Joined:
    Feb 15, 2015
    Posts:
    21
    Just had the same problem and after several tries, my problem solved as this:
    My original script was ok, as far as it matters its syntax and everything, so while i was trying to figure out what was wrong, I pressed at the monoDeveloper menu the Build --> Build All option. The monoDeveloper did build everything and by everything I mean all the scripts from the asserts folder. The outcome was no error in my "trying to load" script, but it did find an error in another script that I didn't even used nowhere in my project. Just had it written while I was trying something else and never used it, keeping it saved in the asserts folder.
    Anyway, the only thing I did, was to delete the unused -with error- script and my script was loaded.
    I don't know if this assumption is correct (i am a unity newbie) but
    I think when there is any compiler error in any script in the assert's (/ project's) folder, errors regarding scripts may occur in the project, whether you use the fault script or not, in the project.

    So check all your other scripts, in the project. This maybe work.
     
  36. imXela

    imXela

    Joined:
    Feb 2, 2015
    Posts:
    5
    instead of creating the script script of the assets just go to the object you want to attach it to and click "Add Component" and then "New Script" and there you go. If you want to move the script into a folder its located in the first assets folder and you can just drag and drop it where you want. This worked for me.
     
  37. jineur

    jineur

    Joined:
    Apr 15, 2015
    Posts:
    1
    Changed

    public class PlayerMoveScript : MonoBehaviour
    {
    }

    back to

    public class playerMoveScript : MonoBehaviour
    {
    }

    and that fixed the problem for me. Could be you renamed the class in the script editor and Unity can't find the file any more.
     
    jeremix98 likes this.
  38. Lucasscremin

    Lucasscremin

    Joined:
    Mar 21, 2015
    Posts:
    1
    Resolve the compile errors and it will work again.
     
  39. 3HORNTHRASHER

    3HORNTHRASHER

    Joined:
    Jul 17, 2015
    Posts:
    1
    This really works,Thx for the so solution :)
     
  40. Jani86

    Jani86

    Joined:
    Nov 10, 2013
    Posts:
    2
    I had the same problem, and "solving" all the compiler errors fixed the problem.
    But this is just unbelievable. I have a compiling error in some class and the Unity losing some capability along with my custom editor scripts.. What kind of environment does that? (Unity 4.6.4 f1)
    Imagine if the transport buses couldn't start in real life until everyone has their shoes properly tied, or worse 3 random people with shoes from the same brand would became unable to stand up.
    Imagine you would became unable to surf the web until you fix your grammar mistakes on the other emailing page which is open.. etc..
     
  41. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Welcome to the forum!

    From a technical point of view, it is logical, because it is only possible to reliably detect for Unity what kind of scripts exist and what they contain, if the compilation was successful. This situation exists for every compiled programming language.

    The code is like a machine that is already being used when you are running the Unity editor. And it is your responsibility that this machine is always working. When you make a change in the code, you replace this whole machine with a new one. If the new one is not working at all, you are warned in the console. Unity tells you that this machine is not usable.
    Now it is up to you, whether you want to revert your changes.
    I personally prefer it that Unity doesn't start to guess how I expected that my machine was supposed to work. Because I know exactly what I had in mind.
     
  42. Jani86

    Jani86

    Joined:
    Nov 10, 2013
    Posts:
    2
    Thanks for the welcome! Sorry for the late answer, my email notification was turned off.

    Now that it works, I guess its okay..
    Still.. Maybe if the warn message wouldn't be something like this: "Can't add script because it doesn't exist!", when it clearly exists and was used until recently and was dragged from one unity window to another.. A message could be something like this (if I understand right): "There was no script compiled with this name. The number of compiled scripts: 0. This could be due to compiler errors in your scripts at Unity Editor start-up." Or something.
    Nothing is more annoying than hearing that something doesn't exist, especially if the program sees it too.
     
  43. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I certainly agree with you that a warning message would be useful!
     
  44. Super___Wang

    Super___Wang

    Joined:
    Dec 19, 2015
    Posts:
    1
    Thank you for solved my promblem!!!!
     
  45. a. s.

    a. s.

    Joined:
    Jan 26, 2016
    Posts:
    1
    I was having this same problem . I did what you did worked out well.
     
  46. Loxyx666

    Loxyx666

    Joined:
    May 14, 2016
    Posts:
    1
    I had this same error to fix it I went into visual studio and changed the public class to the name if my file. This worked for me.