Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

"The referenced script on this Behaviour is missing!"

Discussion in 'Scripting' started by PrzyczajonyLemur, Nov 11, 2016.

  1. PrzyczajonyLemur

    PrzyczajonyLemur

    Joined:
    Mar 5, 2015
    Posts:
    2
    So, I've got this code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Player : MonoBehaviour
    5. {
    6.     void Movement()
    7.     {
    8.         if (Input.GetKey("up"))
    9.         {
    10.             transform.Translate(0, 1, 0);
    11.             if (transform.position.y > 175)
    12.                 transform.Translate(0, -1, 0);
    13.         }
    14.         if (Input.GetKey("down"))
    15.         {
    16.             transform.Translate(0, -1, 0);
    17.             if (transform.position.y < 5)
    18.                 transform.Translate(0, 1, 0);
    19.         }
    20.         if (Input.GetKey("right"))
    21.         {
    22.             transform.Translate(1, 0, 0);
    23.             if (transform.position.x > 115)
    24.                 transform.Translate(-1, 0, 0);
    25.         }
    26.         if (Input.GetKey("left"))
    27.         {
    28.             transform.Translate(-1, 0, 0);
    29.             if (transform.position.x < 5)
    30.                 transform.Translate(1, 0, 0);
    31.         }
    32.     }  
    33.  
    34.     void Start () // Use this for initialization
    35.     {
    36.  
    37.     }
    38.  
    39.     void update () // Update is called once per frame
    40.     {
    41.         Movement();
    42.     }
    43. }
    And Visual Studio compiles it with no problem, but when I go into Unity, I get warnings about missing script on this behaviour. How can I fix this?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    That error has nothing to do with the script's content. Generally it means you renamed a file or altered the file/folder structure outside of unity and it can't find the file it's expecting...
     
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,139
    Do you have any errors in the console? In some cases even encountering another script with an error can create issues. However, as @LeftyRighty said, you may have a misnamed script. If your script is named player but your class is Player for example, that can create the issue.
     
  4. PrzyczajonyLemur

    PrzyczajonyLemur

    Joined:
    Mar 5, 2015
    Posts:
    2
    Ok, it was misnamed script. I feel so terribly stupid right now. Thanks for the help. :)
     
  5. NextWorldVR

    NextWorldVR

    Joined:
    Dec 30, 2017
    Posts:
    14
    Hello! What if the script in question, was made by Selecting an Object , clicking Add Component and New Script, then PASTING in and saving in the project Assets/Scripts folder?
    SO, HOW CAN A SCRIPT BE MISSING FROM AN OBJECT, OR MISNAMED, IF ONE MADE IT ON THE OBJECT ITSELF TO BEGIN WITH? I'm posting my whole relevant problem below, I see the VAST Majority of questions here go unanswered for as long as 6 years, so I think i should paste this in as many places as possible until that one person in 5 billion that like to share info might see it,..


    QUESTION:

    I Asked for help , got sent a script. (Doesn't work...), Came with a Single Quarter-Sentence of instruction (Didn't help...)
    I am SIMPLY trying to MOVE an OBJECT with the OCULUS TOUCH CONTROLLERS. Using 3-axis control, LIKE IN AIRCAR Roll/Pitch/Turn,.. After a literal year of asking finally someone on the OCULUS site sent the following script and said as the only instruction:

    "Attach to gameobject, select handedness, run."

    Of course it does not work ,.. I do not even know how to 'select handedness', perhaps some day I will be psychic but not yet!..

    Here is the 'script' as posted.... I will paste the errors I am getting and the steps I took below it:


    using System.Collections; using System.Collections.Generic; using UnityEngine;

    public class InputEx : MonoBehaviour {

    1. public float TriggerVal;
    2. public float GripVal;
    3. public Vector2 ThumbStickVal;
    4. public bool IsPoint;
    5. public bool IsThumbsUp;
    6. public enum handedness
    7. {
    8. None = 0,
    9. Left =1,
    10. Right =2,
    11. }
    12. public handedness Handedness;
    13. private OVRInput.Controller m_controllerMask;
    14. void Start()
    15. {
    16. if (Handedness == handedness.Left) {
    17. m_controllerMask = OVRInput.Controller.LTouch;
    18. }
    19. if (Handedness == handedness.Right) {
    20. m_controllerMask = OVRInput.Controller.RTouch;
    21. }
    22. }
    23. void Update () {
    24. AnalogInputUpdate ();
    25. DigitalInputUpdate ();
    26. }
    27. void AnalogInputUpdate()
    28. {
    29. if (Handedness == handedness.Left) {
    30. TriggerVal = OVRInput.Get (OVRInput.RawAxis1D.LIndexTrigger);
    31. GripVal = OVRInput.Get (OVRInput.RawAxis1D.LHandTrigger);
    32. ThumbStickVal = OVRInput.Get (OVRInput.Axis2D.PrimaryThumbstick);
    33. }
    34. else if (Handedness == handedness.Right) {
    35. TriggerVal = OVRInput.Get (OVRInput.RawAxis1D.RIndexTrigger);
    36. GripVal = OVRInput.Get (OVRInput.RawAxis1D.RHandTrigger);
    37. ThumbStickVal = OVRInput.Get (OVRInput.Axis2D.SecondaryThumbstick);
    38. }
    39. }
    40. void DigitalInputUpdate()
    41. {
    42. //capacitive point and thumbs up
    43. IsPoint = !(OVRInput.Get (OVRInput.Touch.PrimaryIndexTrigger, m_controllerMask));
    44. IsThumbsUp = !OVRInput.Get(OVRInput.NearTouch.PrimaryThumbButtons, m_controllerMask);
    45. //digital buttons down
    46. if (OVRInput.GetDown (OVRInput.RawButton.X , m_controllerMask)) {
    47. Debug.Log ("X Down");
    48. }
    49. if (OVRInput.GetDown (OVRInput.RawButton.Y , m_controllerMask)) {
    50. Debug.Log ("Y Down");
    51. }
    52. if (OVRInput.GetDown (OVRInput.RawButton.A , m_controllerMask)) {
    53. Debug.Log ("A Down");
    54. }
    55. if (OVRInput.GetDown (OVRInput.RawButton.B , m_controllerMask)) {
    56. Debug.Log ("B Down");
    57. }
    58. if (OVRInput.GetDown (OVRInput.RawButton.Start , m_controllerMask)) {
    59. Debug.Log ("Menu Button Down");
    60. }
    61. //digital buttons up
    62. if (OVRInput.GetUp (OVRInput.RawButton.X , m_controllerMask)) {
    63. Debug.Log ("X Up");
    64. }
    65. if (OVRInput.GetUp (OVRInput.RawButton.Y , m_controllerMask)) {
    66. Debug.Log ("Y Up");
    67. }
    68. if (OVRInput.GetUp (OVRInput.RawButton.A , m_controllerMask)) {
    69. Debug.Log ("A Up");
    70. }
    71. if (OVRInput.GetUp (OVRInput.RawButton.B , m_controllerMask)) {
    72. Debug.Log ("B Up");
    73. }
    74. if (OVRInput.GetUp (OVRInput.RawButton.Start , m_controllerMask)) {
    75. Debug.Log ("Menu Button Up");
    76. }
    77. }
    }

    ========================================================================================================================================================================

    Here is what I did with this mysterious unexplained, un- 'commented' script:

    1) I create a New Unity Project and import Oculus Utilities.

    2) I create a cube, I drag in OVR Camera Rig make it a child of the cube..

    3) I select Cube, add component New Script and paste in your text in Visual Studio. I save the file as fly.cs

    4) I set player setting for VR Enabled and Oculus (No open VR)

    5) I run the game window, try every single button and grips etc on each oculus controller, Nothing at all,.

    So, That's where i'm at, I look at the Cube inspector, it does say at the top of the Script Component entry 'NOTHING SELECTED' (???) The CUBE IS SELECTED!! The errors I get are:

    1) The referenced script on this Behaviour is missing! (referenced Script? I only have one Script and it's fly.cs ... It is Definately in the Project Folder, That where I created it, as you can see above, I addeda 'new script' the the cube, then saved it in Assets/Scripts)

    2) The referenced script on this Behaviour (Game Object 'Cube') is missing!

    What is this 'Referenced Script'? I only HAVE one SCRIPT,.. It is most certainly IN THE PROJECT FOLDER!! ???????? I will attach a screen grab, of the Inspector and the Console,.
    http://tinypic.com/r/5n84fp/9



    http://i68.tinypic.com/5n84fp.jpg

    <a href="http://tinypic.com?ref=5n84fp" target="_blank"><img src="http://i68.tinypic.com/5n84fp.jpg" border="0" alt="Image and video hosting by TinyPic"></a>
    <a href="http://tinypic.com?ref=5n84fp" target="_blank"><img src="http://i68.tinypic.com/5n84fp.jpg" border="0" alt="Image and video hosting by TinyPic"></a>
     
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I could say several things about your post, however it's almost not worth it.. so

    rename your script and file to have the same name and save the changes and see if something positive happens.
     
  7. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,840
    You're wrong and you shouldn't.

    You have to have the monobehaviour class named as the filename in Unity. Either you should call your file InputEx.cs or should have fly class in the file.
     
  8. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,139
    Doesn't matter how you create it. If your file name is different from the script name itself, it can't find it.
    As @LurkingNinjaDev posted.

    Your filename is fly.cs
    Your script name is InputEx (the class)

    They don't match. It's like making a reservation at a restaurant and telling them your name is Tom and when you show up, your ID says your name is Bill.
     
  9. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    It may seem that the vast majority of questions here go unanswered when you don't read or understand the comments that answer them. In this case the answer was posted in the first comment and again restated by the OP in the comment right above yours. Script names matter for Monobehaviour scripts.

    Also use Code tags when posting code. It is described in the sticky thread at the top of this forum.