Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by jriddensdale · Nov 15, 2015 at 06:15 PM · nullreferenceexceptionreferencenullminecraft

Null Reference Exeption??

So as some might know, I am making a minecraft command block as a project for school and I am getting a Null reference exeption for a random reason. I checked my whole scene to see if any thing had my script that had no assined vars and its clear! So is it in my script??

 #pragma strict
  
  //The string that is edited in the text field
  var Texture1 : Texture2D;
  var Texture2 : Texture2D;
  var Texture3 : Texture2D;
  var Impulse : boolean;
  var Chain : boolean;
  var Repeting : boolean;
  public var stringToEdit : String;
  var creativeMode : flyControllerScript;
  var survivalMode : MonoBehaviour;
  //The command as entered by the player
  public var command : String;
  public var command2 : String;
  public var command3 : String;
  public var command4 : String;
  var rigidbdy : Rigidbody;
  //Boolean to track when the player clicks to enable the text field
  public var clicked : boolean;
  //Boolean to track when the player has confirmed the command to enter
  public var shouldCheckCommand : boolean;
  
  function Start()
  { 
      survivalMode.enabled = true;     
       creativeMode.enabled = false;
      //Initialize variables
      stringToEdit = "/type in here";
      clicked = false;
      shouldCheckCommand = false;
      
  }
  function OnMouseDown ()
  {
      stringToEdit = "/type in here";
     clicked = true;
  }
  
  function Update()
  {
      
      //Check for the mouse click - the text field is invisible
      //if(Input.GetMouseButtonDown (0) && clicked == false)
      //{
          //Reset the string to default
        //  stringToEdit = "/type in here";
          //clicked = true;
      //}
      //Check for the Return/Enter key - the text field is visible
       if (Input.GetKeyDown(KeyCode.Return) && clicked == true)
      {
          command = stringToEdit; //Here is the key part - the string from the text field is assigned to the command variable
          command2 = stringToEdit; //Here is the key part - the string from the text field is assigned to the command variable
          clicked = false;
          shouldCheckCommand = true;
      }
      
      //Check if the player has confirmed the command entered
      if (shouldCheckCommand == true)
      {
          CheckCommand();
      }
  }
  
  function CheckCommand()
  {
      //Check which command was entered and take the appropriate action
      if (command == "/kill" || command == "/Kill")
      {
          Debug.Log("Kill the player");
          Application.LoadLevel(Application.loadedLevel);
          
          
          if(Repeting == true)
           {
              Debug.Log("Kill the player");
              Application.LoadLevel(1);          
           }
      }
      
      shouldCheckCommand = false;
      
           //Check which command was entered and take the appropriate action
      if (command2 == "/help"|| command2 == "/Help")
      {
          Debug.Log("The list of commands: /gamemode 0 (change to survival) /gamemode 1 (change to creative) /kill (kills player) /help (list of commands) More Commands comming soon");
            while (Repeting == true)
           {
               Debug.Log("The list of commands: /gamemode 0 (change to survival) /gamemode 1 (change to creative) /kill (kills player) /help (list of commands) More Commands comming soon");
           }
 
      }
      
      shouldCheckCommand = false;
      
      
      if (command3 == "/gamemode 0"|| command3 == "/gamemode survival")
      {
          Debug.Log("Gamemode is now survival");
          creativeMode = GetComponent(flyControllerScript); 
            survivalMode.enabled = true;
            creativeMode.enabled = false;
            rigidbdy.GetComponent.<Rigidbody>().isKinematic = true;
          rigidbdy.GetComponent.<Rigidbody>().detectCollisions = true;
            
            if (Repeting == true)
           {
              Debug.Log("Warning Code has protected unity from crashing!");
           }
 
      }
      
      shouldCheckCommand = false;
      
           if (command4 == "/gamemode 1"|| command4 == "/gamemode creative")
      {    
          
          Debug.Log("Gamemode is now Creative");
          creativeMode = GetComponent(flyControllerScript); 
            creativeMode.enabled = true;
            survivalMode.enabled = false;
          rigidbdy.GetComponent.<Rigidbody>().isKinematic = true;
          rigidbdy.GetComponent.<Rigidbody>().detectCollisions = false;
            
            
            if (Repeting == true)
           {
              Debug.Log("Warning Code has protected unity from crashing!");
 
           }
 
      }
      
      shouldCheckCommand = false;
  }
       
  function OnGUI()
  {
      if(clicked == true)
      {    
          stringToEdit = GUI.TextField (Rect (0, 100, 200, 200), stringToEdit, 200);
          GUI.Button(Rect(0, 0, 200, 50), "Command Block Interface");
          if (GUI.Button(Rect(0, 300, 200, 50), "Impulse")){
              GetComponent.<Renderer>().material.mainTexture = Texture1;
              Impulse = true;
          }
          if (GUI.Button(Rect(0, 350, 200, 50), "Chain")){
              GetComponent.<Renderer>().material.mainTexture = Texture2;
              Chain = true;
          }
          if (GUI.Button(Rect(0, 400, 200, 50), "Repeting")){
              GetComponent.<Renderer>().material.mainTexture = Texture3;
              Repeting = true;
          }
         
         if (GUI.Button(Rect(0, 500, 200, 50), "Done")){
              clicked = false;
          }
      }
  }
 

Please help !

Comment
Add comment · Show 8
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 Jessespike · Nov 15, 2015 at 07:18 PM 0
Share

Where is the error taking place? The console will tell you. For example, this mockup says the error is on line 21

 NullReferenceException: Object reference not set to an instance of an object
 $$anonymous$$yScript.Start () (at Assets/$$anonymous$$yScript.cs:21)
avatar image jriddensdale Jessespike · Nov 15, 2015 at 07:59 PM 0
Share

Line 103 thats where it takes place

avatar image Jessespike jriddensdale · Nov 16, 2015 at 01:47 AM 0
Share

creative$$anonymous$$ode is null. This can happen when GetComponent can't find the component. Does the GameObject have a flyControllerScript attached to it?

Show more comments
avatar image Jessespike · Nov 16, 2015 at 10:50 PM 0
Share

Then something else is wrong. flyControllerScript was a guess, since creative$$anonymous$$ode mode is on line 103. One of your objects is losing a reference, or a GetComponent is failing to return. I wonder if the problem lies within flyControllerScript itself.

avatar image jriddensdale Jessespike · Nov 16, 2015 at 11:32 PM 0
Share

Hmmm..... But what?

avatar image jriddensdale Jessespike · Nov 16, 2015 at 11:35 PM 0
Share

This is what the error is NullReferenceException: Object reference not set to an instance of an object CommandBlockAI+$CheckCommand$6+$.$$anonymous$$oveNext () (at Assets/Redstone/CommandBlock/Scripts/CommandBlockAI.js:103) UnityEngine.$$anonymous$$onoBehaviour:StartCoroutine_Auto(IEnumerator) CommandBlockAI:Update() (at Assets/Redstone/CommandBlock/Scripts/CommandBlockAI.js:62)

avatar image jriddensdale Jessespike · Nov 16, 2015 at 11:37 PM 0
Share

Here is the flyControllerScript

var lookSpeed = 15.0; var moveSpeed = 15.0;

var rotationX = 0.0; var rotationY = 0.0;

function Update () { rotationX += Input.GetAxis("$$anonymous$$ouse X")*lookSpeed; rotationY += Input.GetAxis("$$anonymous$$ouse Y")*lookSpeed; rotationY = $$anonymous$$athf.Clamp (rotationY, -90, 90);

 transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
 transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
 
 transform.position += transform.forward*moveSpeed*Input.GetAxis("Vertical");
 transform.position += transform.right*moveSpeed*Input.GetAxis("Horizontal");

}

0 Replies

· Add your reply
  • Sort: 

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

33 People are following this question.

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

Related Questions

Component refrence goes null randomly? 3 Answers

I don't understand NullReferenceException: Object reference not set to an instance of an object 0 Answers

NullReferenceException: Object reference not set to an instance of an object error 0 Answers

Coroutine Issue 1 Answer

I have a NullReferenceException problem how do I fix this error 0 Answers


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