Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Object reference not set to an instance of an Object C#

Discussion in 'Scripting' started by georetro, Feb 4, 2014.

Thread Status:
Not open for further replies.
  1. georetro

    georetro

    Joined:
    Jan 18, 2013
    Posts:
    218
    Hey guys! I am pretty new to C# and am currently making my second game using this language. The game is a clone of Breakout and I have been doing really well so far but I am stuck as an error is being shown in the console. After my ball goes into the Trigger zone and tries to re-spawn on the Paddle.

    My Death Field Script:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DeathFieldScript : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.    
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update () {
    13.    
    14.     }
    15.  
    16.     void OnTriggerEnter(Collider other){
    17.         BallController ballController = other.GetComponent<BallController>();
    18.  
    19.         if(ballController){
    20.             ballController.Die();
    21.         }
    22.     }
    23. }
    And also my BallController Script:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class BallController : MonoBehaviour {
    5.    
    6.     // Use this for initialization
    7.     void Start () {
    8.     }
    9.    
    10.     // Update is called once per frame
    11.     void Update () {
    12.        
    13.     }
    14.  
    15.     public void Die(){
    16.         GameObject paddleGameObject = GameObject.Find("paddle");
    17.         Destroy(this.gameObject);
    18.         PaddleController paddleController = paddleGameObject.GetComponent<PaddleController>();
    19.         paddleController.SpawnBall();
    20.     }
    21. }
    The exact error message is here:

    NullReferenceException: Object reference not set to an instance of an object
    BallController.Die () (at Assets/Scripts/Breakout/BallController.cs:18)
    DeathFieldScript.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Breakout/DeathFieldScript.cs:20)

    Thanks to anyone who can help :) This is my second game using C#
     
  2. GameScience

    GameScience

    Joined:
    Dec 20, 2013
    Posts:
    32
    Unity is telling you that one of the things in line 18 of the BallController script doesn't exist. In this case, that would be either the variable paddleGameObject or it's component PaddleController. Make sure that there is such a component attached to the paddle object, and make sure that it is called "paddle".

    I don't know if this is the problem, but you should have Destroy(this.gameObject) be the last thing this function does. You don't want to destroy the object before you finish using it.
     
  3. georetro

    georetro

    Joined:
    Jan 18, 2013
    Posts:
    218
    Oh man. Thank you so much :) The problem was that I thought that when I was typing Find("paddle"), I thought that that meant the tag not the actual GameObject. I changed it to "Player" and everything is fixed now. Thank you once again :)
     
  4. GameScience

    GameScience

    Joined:
    Dec 20, 2013
    Posts:
    32
    No problem, man. And good luck with your games.
     
  5. georetro

    georetro

    Joined:
    Jan 18, 2013
    Posts:
    218
    Thanks. And you too :)
     
  6. Brogan89

    Brogan89

    Joined:
    Jul 10, 2014
    Posts:
    244
    Hi, I have had some problem.
    I am very new to C# and was following along with Mike Geig's tutorial on "Fun With Explosions!"
    I am typing out exactly how he does it, and even pausing to make sure, but I still am getting this same error.

    I am hoping someone can help.
    Unity is saying the problem is on line 14
    This is my script i am writing:


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ExplosionScript : MonoBehaviour
    5. {
    6.  
    7.     public float force;
    8.  
    9.  
    10.     void Update ()
    11.     {
    12.         if (Input.GetMouseButton (0))
    13.         {
    14.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    15.                 RaycastHit hit;
    16.          
    17.             if(Physics.Raycast(ray, out hit, 100))
    18.             {
    19.                 rigidbody.AddExplosionForce(force, hit.point, 5);
    20.  
    21.             }
    22.         }
    23.  
    24.  
    25.  
    26.  
    27.     }
    28. }
     
  7. laurelhach

    laurelhach

    Joined:
    Dec 1, 2013
    Posts:
    229
    Georetro,

    This is a common discussion here on the forum, but instead of using .Find, you could use FindGameObjectWithTag(), apparently this is much faster. It might not be if you don't have a lot of objects, but if your scene has a lot, it might help a bit.

    Cheers.
     
    Howardjek and Paduik like this.
  8. Elrien

    Elrien

    Joined:
    Jul 15, 2014
    Posts:
    32
    hi, i'm having now a similar problem but i'm not sure how to fix this, could you help me? this is my script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Patrol : MonoBehaviour {
    5.     public Transform[] patrolPoints;
    6.     public float moveSpeed;
    7.     private int currentPoint;
    8.     // Use this for initialization
    9.     void Start () {
    10.         transform.position = patrolPoints[0].position;
    11.         currentPoint = 0;
    12.     }
    13.  
    14.    
    15.     // Update is called once per frame
    16.     void Update () {
    17.  
    18.         if (transform.position == patrolPoints[currentPoint].position)
    19.         {
    20.             currentPoint++;
    21.         }
    22.         if (currentPoint >= patrolPoints.Length)
    23.         {
    24.             currentPoint = 0;
    25.         }
    26.  
    27.         transform.position = Vector3.MoveTowards (transform.position, patrolPoints [currentPoint].position, moveSpeed * Time.deltaTime);
    28.     }
    29. }
    30.  
    this is the error: NullReferenceException: Object reference not set to an instance of an object
    Patrol.Update () (at Assets/Scripts/Patrols.cs:18)


    but (at least this is what i understood from the tutorial i'm following) this is not meant to be reffered to an object (i mean not line 18) except the enemy (which is referred to)... do you understand what i'm trying to say? i'm sorry, but i find it difficult to explain... anyway_ can you help me! tahtks:)
     
  9. laurelhach

    laurelhach

    Joined:
    Dec 1, 2013
    Posts:
    229
    Did you add your objects in your variable patrolPoints in the inspector?
    Maybe your patrolPoints array is empty. You should start looking at that first.

    Let me know how it goes.

    PS: Also I am not quite sure, but length return the size, so if you start your counter at 0, you will have a position that will be looking for an index that doesn't exists. Length of 5 for example will return [0], [1], [2], [3] and [4], not [5]. Do u see what I mean?
     
  10. Elrien

    Elrien

    Joined:
    Jul 15, 2014
    Posts:
    32
    hi, thanks for your reply. i'm sorry, but how exactly can i add an object to a variable in the inspector? and i forgot to say that before this worked, but if i add another patrol point (and add the size in the enemy inspector) it doesn't work... in the trailer itself it used Length (
    this is the trailer, you can see the code at 20:37 more or less)
    Schermata 2014-07-17 alle 03.15.13.png this is the enemy inspector

    i'm sorry, what should i change? thank you for your time
     
    StarC0der likes this.
  11. laurelhach

    laurelhach

    Joined:
    Dec 1, 2013
    Posts:
    229
    Well, from the video, it looks really simple.
    So you have your enemy, with the script Patrol attached to it?
    Do you exactly have the same setup and the same script?

    You do the same way he did when adding a new patrol in the array. You drag and drop the patrol from the inspector in the Patrol Points script (the screen shot you have above).

    Are all your elements (from the array in the inspector) filled wit a patrol point Transform?

    Please make sure you don't have two scripts of Patrol attached on the same enemy, that could be one of the issue if they don't have the same size. I saw he had two scripts attached to the cube, not sure if that was on purpose.
     
  12. Elrien

    Elrien

    Joined:
    Jul 15, 2014
    Posts:
    32
    yes, i have the script attached and the screen shot was from my inspector, so all the three sizes are filled with the patrol points. i've checked and i have just one script...
    this is my enemy inspector right now: Schermata 2014-07-18 alle 17.24.32.png

    and this is my script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Patrol : MonoBehaviour {
    5.     public Transform[] patrolPoints;
    6.     public float moveSpeed;
    7.     private int currentPoint;
    8.     // Use this for initialization
    9.     void Start () {
    10.         transform.position = patrolPoints[0].position;
    11.         currentPoint = 0;
    12.     }
    13.  
    14.    
    15.     // Update is called once per frame
    16.     void Update () {
    17.  
    18.         if (transform.position == patrolPoints[currentPoint].position)
    19.         {
    20.             currentPoint++;
    21.         }
    22.         if (currentPoint >= patrolPoints.Length)
    23.         {
    24.             currentPoint = 0;
    25.         }
    26.  
    27.         transform.position = Vector3.MoveTowards (transform.position, patrolPoints [currentPoint].position, moveSpeed * Time.deltaTime);
    28.     }
    29. }
    30.  
    thank you so much once again for your help
     
    Djent3D likes this.
  13. Elrien

    Elrien

    Joined:
    Jul 15, 2014
    Posts:
    32
    just so you know, i've solved the problem by making the game all over again. thanks anyway for your time:)
     
    gilemaeda likes this.
  14. kaarme

    kaarme

    Joined:
    May 1, 2014
    Posts:
    177
    Code (CSharp):
    1. GameObject Cube = GameObject.Find("Cube");
    2. Cube.SetActive(false);
    I have this in my FixedUpdate, and the Cube gameobject is loaded but it still says object reference not set to an instance of an object.
     
    Voznov likes this.
  15. kelvinwop

    kelvinwop

    Joined:
    Dec 15, 2014
    Posts:
    36
    I have the exact same problem,
    Code (CSharp):
    1. Rigidbody2D newBullet;
    2. newBullet = Instantiate(bullet, bs.position, bs.rotation) as Rigidbody2D;
    3. newBullet.AddForce(bs.forward * 10000);
    NullReferenceException: Object reference not set to an instance of an object
    shooting.Update () (at Assets/Scripts/shooting.cs:60)

    the bullet gets instantiated right in front of the character, doesn't move, and that error comes up.
     
  16. Methaq

    Methaq

    Joined:
    Dec 7, 2014
    Posts:
    4
    that is happen to me when i used the script of camera smooth follow y plez
     
  17. Cooooo

    Cooooo

    Joined:
    Feb 23, 2015
    Posts:
    1
    I have the same error... And I can't find any solutions...

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using System.Text;
    3. using System.IO;
    4. using System.Collections;
    5. using System.Text.RegularExpressions;
    6. using UnityEngine;
    7. using System;
    8.  
    9.  
    10. public class Recup_donnees_6bis : MonoBehaviour {
    11.  
    12.     class Data_struct {
    13.  
    14.         public String marker_name ;
    15.         public Vector3 [] positions ;
    16.  
    17.     }
    18.  
    19.         private Data_struct [] nv_data ;
    20.  
    21.         GameObject [] body ;
    22.         string[][] datas;
    23.    
    24.         int cpt = 0 ; // Int
    25.  
    26.  
    27.     // When the script instance is being loaded
    28.  
    29.     void Awake ()
    30.  
    31.     {
    32.         Application.targetFrameRate = 25;
    33.     }
    34.  
    35.  
    36.     // Use this for initialization
    37.  
    38.     void Start()
    39.  
    40.     {
    41.         body = new GameObject[55];
    42.  
    43.         body [0] = GameObject.Find ("RightUpLeg");
    44.         body [1] = GameObject.Find ("LeftUpLed");
    45.         body [5] = GameObject.Find ("Neck");
    46.         body [6] = GameObject.Find ("RightArm");
    47.         body [7] = GameObject.Find ("LeftArm");
    48.         body [8] = GameObject.Find ("Throat");
    49.         body [9] = GameObject.Find ("Spine1");
    50.         body [11] = GameObject.Find ("Spine");
    51.         body [12] = GameObject.Find ("Hips");
    52.         body [13] = GameObject.Find ("Scalp");
    53.         body [14] = GameObject.Find ("HeadTop_End");
    54.         body [15] = GameObject.Find ("R_Temple");
    55.         body [16] = GameObject.Find ("L_Temple");
    56.         body [17] = GameObject.Find ("RightForeArm");
    57.         body [21] = GameObject.Find ("RightHand");
    58.         body [23] = GameObject.Find ("RightHandIndex1");
    59.         body [24] = GameObject.Find ("RightHandThumb2");
    60.         body [25] = GameObject.Find ("RightHandPinky2");
    61.         body [26] = GameObject.Find ("LeftForeArm");
    62.         body [30] = GameObject.Find ("LeftHand");
    63.         body [32] = GameObject.Find ("LeftHandIndex1");
    64.         body [33] = GameObject.Find ("LeftHandThumb2");
    65.         body [34] = GameObject.Find ("LeftHandPinky2");
    66.         body [35] = GameObject.Find ("RightLed");
    67.         body [38] = GameObject.Find ("RightFoot");
    68.         body [41] = GameObject.Find ("RightFootToeBase_End");
    69.         body [42] = GameObject.Find ("RightToeBase");
    70.         body [45] = GameObject.Find ("LeftLed");
    71.         body [48] = GameObject.Find ("LeftFoot");
    72.         body [51] = GameObject.Find ("LeftFootToeBase_End");
    73.         body [53] = GameObject.Find ("LeftToeBase");
    74.  
    75.         StreamReader reader = new StreamReader ("Suj01_PI_DP_C00_1.txt");
    76.        
    77.         using (reader) {
    78.            
    79.             string line = " ";
    80.             int lineNumber = 10;
    81.  
    82.                 for (int i = 0; i < lineNumber; i++)
    83.                 {
    84.                     line = reader.ReadLine();
    85.                     if (line == null) return;
    86.                 }
    87.            
    88.             string line_10;
    89.             line_10 = line;
    90.             string[] names = line_10.Split (new String[] {",",",,,"},StringSplitOptions.RemoveEmptyEntries);
    91.  
    92.             nv_data = new Data_struct[names.Length] ;
    93.  
    94.                 for (int i =0 ; i< names.Length; ++i )
    95.                 {
    96.                     nv_data[i] = new Data_struct () ;
    97.                     nv_data[i].marker_name = names[i] ;
    98.                 }
    99.  
    100.            
    101.             line = reader.ReadLine();
    102.             string line_11;
    103.             line_11 = line;
    104.             string[] axes = line_11.Split(new String[] {"Field #",","},StringSplitOptions.RemoveEmptyEntries);
    105.  
    106.             datas = new string[4000][];
    107.  
    108.             int counter = 0;
    109.             while (line != null) {
    110.                 counter++;
    111.                 line = reader.ReadLine();
    112.  
    113.                 if (line == "ANALOG")
    114.                 break ;
    115.  
    116.                 if ((counter %3) != 1)                    continue;
    117.  
    118.                 string lines_datas;
    119.                 lines_datas = line;
    120.                 datas[cpt] = lines_datas.Split(new string[] {","},StringSplitOptions.RemoveEmptyEntries);
    121.  
    122.                 line = reader.ReadLine();
    123.  
    124.                 cpt ++ ;  
    125.                
    126.             }
    127.  
    128.                 for (int i = 0 ; i < cpt ; ++i ) // We parse every line of datas
    129.                 {
    130.                     for (int j = 1 ; j < names.Length+1 ; j++ )
    131.                 {
    132.                     nv_data[j-1].positions = new Vector3[cpt];
    133.                
    134.                 nv_data[j-1].positions[i].x = float.Parse(datas[i][j*3-2]);
    135.                 nv_data[j-1].positions[i].y = float.Parse(datas[i][j*3-1]);
    136.                 nv_data[j-1].positions[i].z = float.Parse(datas[i][j*3]);
    137.  
    138.                 }
    139.                
    140.             }
    141.  
    142.         }
    143.        
    144.      }
    145.  
    146.     // Update is called once per frame
    147.     void Update () {
    148.  
    149.         // To associate names_markers to avatar_joints :
    150.  
    151.         for (int i = 0; i < cpt; ++i) {
    152.  
    153.                         for (int k = 0; k < body.Length; ++k)
    154.  
    155.                                 body [k].transform.position = nv_data[k].positions[i];
    156.                                 Debug.Log(body[1].transform.position);
    157.  
    158.                 }
    159.  
    160.     }
    161.  
    162. }
    My problem is about the line :
    body [k].transform.position = nv_data[k].positions;

    I think it's because the string "nv_data" has been initialized and used in "void start ()" and here I'm in "void update". How can I used this string in void update () ?

    I need this code to make an animation : combining datas (get from the text file) to an avatar.
    Datas in text file corresponds to names of markers (on real human body) and the avatar has some joints. So I associated some markers (names) to joints. And now I want that the datas concerning positions of markers (names) would be associated to the joints that I have chosen.

    Could you help me, please ?

    I'm not english, so my apologies for my writing.

    Thank you
     
  18. Dan Snow

    Dan Snow

    Joined:
    Mar 5, 2015
    Posts:
    2
    Im trying to expand on the Unity Space Shooter Tutorial and im getting the error
    "NullReferenceException: Object reference not set to an instance of an object"

    Im quite new to unity.

    Any help would be greatly appreciated.

    using UnityEngine;
    using System.Collections;

    public class Done_DestroyByContact : MonoBehaviour
    {
    public GameObject explosion;
    public GameObject playerExplosion;
    public int scoreValue;
    private Done_GameController gameController;
    private Respawn respawn;





    void Start ()
    {
    GameObject gameControllerObject = GameObject.FindGameObjectWithTag ("GameController");
    if (gameControllerObject != null)
    {
    gameController = gameControllerObject.GetComponent <Done_GameController>();
    }
    if (gameController == null)
    {
    Debug.Log ("Cannot find 'GameController' script");
    }
    }

    void OnTriggerEnter (Collider other)
    {
    if (other.tag == "Boundary" || other.tag == "Enemy")
    {
    return;
    }

    if (explosion != null)
    {
    Instantiate(explosion, transform.position, transform.rotation);
    }

    if (other.tag == "Player")
    {
    gameController.UpdateLives();
    Instantiate(playerExplosion, other.transform.position, other.transform.rotation);

    }

    gameController.AddScore(scoreValue);
    Destroy (other.gameObject);
    Destroy (this.gameObject);
    respawn.CheckLives ();
    Debug.Log("AFTER CHECK LIVES");

    }
    }
     
  19. yout897

    yout897

    Joined:
    Apr 5, 2015
    Posts:
    2
    Getting this error when I left click and it says it is in the lines 28 and 15 so I have no idea what to do. Any help will do.

    using UnityEngine;
    using System.Collections;

    public class PlayerShooting : MonoBehaviour {

    public float firerate = 0.5f;
    float cooldown = 0;
    public float damage = 25f;

    // Update is called once per frame
    void Update () {

    cooldown -= Time.deltaTime;
    if (Input.GetButton ("Fire1")) {
    fire ();

    }


    }
    void fire(){
    if (cooldown > 0) {
    return;

    }


    Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
    Transform hitTransform;
    Vector3 hitPoint;

    hitTransform = FindClosestHitObject (ray, out hitPoint);

    if (hitTransform != null) {
    Debug.Log ("Fired Gun");


    Health h = hitTransform.GetComponent<Health>();

    while(h == null && hitTransform.parent){
    hitTransform = hitTransform.parent;
    h = hitTransform.GetComponent<Health>();
    }


    if(h !=null){
    h.TakeDamage(damage);
    }

    }

    cooldown = firerate;
    }

    Transform FindClosestHitObject(Ray ray, out Vector3 hitPoint){

    RaycastHit[] hits = Physics.RaycastAll (ray);

    Transform closestHit = null;
    float distance = 0;
    hitPoint = Vector3.zero;

    foreach (RaycastHit hit in hits) {
    if(hit.transform != this.transform && (closestHit==null || hit.distance < distance )){

    closestHit = hit.transform;
    distance = hit.distance;
    hitPoint = hit.point;
    }
    }
    return closestHit;
    }
    }
     
  20. PiousCape262

    PiousCape262

    Joined:
    Apr 20, 2015
    Posts:
    1
    Hey I am getting the same problem I am using 2 scripts one script uses a function from another script

    This script is called Attack

    using UnityEngine;
    using System.Collections;
    public class Attack : MonoBehaviour {
    Animator animator;
    Weapon weapon;
    void Update () {
    animator = GetComponent<Animator> ();
    if (Input.GetKey (KeyCode.Space)) {
    animator.SetBool ("Attack", true);
    weapon.WeaponAtk(true, 1);
    }
    else
    {
    animator.SetBool ("Attack", false);
    }
    }
    }

    And this is the script called Weapon with the function inside of it called WeaponAtk

    using UnityEngine;
    using System.Collections;
    public class Weapon : MonoBehaviour{
    public bool Attacking;
    public int Dmg;
    public void WeaponAtk (bool attacking, int dmg)
    {
    attacking = Attacking;
    dmg = Dmg;
    if(attacking == true)
    {
    print ("Damage Given " + dmg);
    }
    }
    }
     
  21. mtibo62

    mtibo62

    Joined:
    May 3, 2015
    Posts:
    8
    Hello, I am using the very first and easiest tutorial on the Unity website were you control a ball. However, after the very first video of script I am already having problems XD
    this is the code I have:

    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    public float speed;
    private Rigidbody rb;

    void start ()
    {
    rb = GetComponent<Rigidbody>();
    }

    void FixedUpdate()
    {
    float movevertical = Input.GetAxis ("Vertical");
    float movehorizontal = Input.GetAxis ("Horizontal");

    Vector3 movment = new Vector3 (movehorizontal, 0.0f, movevertical);
    rb.AddForce(movment * speed);
    }
    }



    And the error it is giving me is
    NullReferenceException: Object reference not set to an instance of an object
    PlayerController.FixedUpdate () (at Assets/Scripts/PlayerController.cs:20)

    Sorry if this is a bad question to ask but since I am first starting I really want to learn exactly what is happening
     
  22. Zaladur

    Zaladur

    Joined:
    Oct 20, 2012
    Posts:
    392
    Capitalize your Start() function. It isn't being called right now, which means the variable rb is not being set, which is the cause of your nullReference.
     
    cudosmoney and mahajan.arvind like this.
  23. mtibo62

    mtibo62

    Joined:
    May 3, 2015
    Posts:
    8
    That didn't seem to fix it. However, now when ever I start the game the ball begins to start to roll very slowly and then speeds up, but I am never controlling the ball.
     
  24. Zaladur

    Zaladur

    Joined:
    Oct 20, 2012
    Posts:
    392
    Are you still getting NullReference Exceptions? If so, check that a rigidbody is attached to the object in question (the same one with this script attached).

    If you are pressing nothing and the ball is rolling, debug.log your movement Vector3 to make sure the values are truly zero. Also consider checking inclines, as maybe gravity is causing the roll.
     
  25. mtibo62

    mtibo62

    Joined:
    May 3, 2015
    Posts:
    8
    Hmmm... something has changed, I can now move the ball. However, it isn't rolling, but it seems to be sliding, also this sliding makes it extremely hard to control.
     
  26. JUANCAMARGO

    JUANCAMARGO

    Joined:
    May 9, 2015
    Posts:
    10
    I'm having issues with the same error:

    NullReferenceException: Object reference not set to an instance of an object
    GameController+<SpawnWaves>c__Iterator2.MoveNext () (at Assets/Scripts/GameController.cs:43)

    I was doing the Space Shooter tutorial and everything was fine, when i tryed to make some changes to the code that the tutorial provide I get that error.
    What I'm trying to do is increase the speed of the asteroids every time that the wave of x asteroids ends or in other words every time that the for cycle ends. But I don't know how to do that. I tried with the code below but the error apears. I'll love some help here.
    This is the game controller code, where I'm trying to increase the speed.
    Code (CSharp):
    1. public class GameController : MonoBehaviour
    2. {
    3.     //Objeto para referencias a los enemigos
    4.     public GameObject Hazard;
    5.     public Vector3 SpawnValues;
    6.     public int hazardCount;
    7.     public float spawnWait;
    8.     public float startWait;
    9.     public float waveWait;
    10.     public GUIText ScoreText;
    11.     private int score, newspeed;
    12.     private Mover mover;
    13.  
    14.     void Start()
    15.     {
    16.         score = 0;
    17.         newspeed = 1;
    18.         UpdateScore();
    19.         StartCoroutine(SpawnWaves());
    20.         GameObject objeto_mover = GameObject.FindWithTag("Objeto");
    21.         if (objeto_mover != null)
    22.         {
    23.             mover = objeto_mover.GetComponent<Mover>();
    24.         }
    25.         if (objeto_mover == null)
    26.         {
    27.             Debug.Log("Cannot Find GameController Script");
    28.         }
    29.        
    30.     }
    31.     //Spawning enemies
    32.     IEnumerator SpawnWaves()
    33.     {
    34.         yield return new WaitForSeconds(startWait);
    35.         while (true)
    36.         {          
    37.             for (int i = 0; i < hazardCount; i++)
    38.             {
    39.                 Vector3 SpawnPosition = new Vector3(Random.Range(-SpawnValues.x, SpawnValues.x), SpawnValues.y, SpawnValues.z);
    40.                 Quaternion SpawnRotation = Quaternion.identity;
    41.                 Instantiate(Hazard, SpawnPosition, SpawnRotation);
    42.                 yield return new WaitForSeconds(spawnWait);
    43.                 [U]mover.AddSpeed(newspeed);[/U]
    44.             }
    45.            
    46.             yield return new WaitForSeconds(waveWait);
    47.         }      
    48.     }
    49.  
    50.     public void AddScore(int NewScoreValue)
    51.     {
    52.         score += NewScoreValue;
    53.         UpdateScore();
    54.        
    55.     }
    56.  
    57.     void UpdateScore()
    58.     {
    59.         ScoreText.text = "Score: " + score;
    60.     }
    61. }
    62.  
    This is the code that moves the asteroids.

    Code (CSharp):
    1. public class Mover : MonoBehaviour
    2. {
    3.     public float speed;
    4.     void Start()
    5.     {
    6.         Rigidbody rigidbody = (Rigidbody)GetComponent(typeof(Rigidbody));
    7.         rigidbody.velocity = transform.forward * speed;
    8.     }
    9.  
    10.     public void AddSpeed(int NewSpeed)
    11.     {
    12.         speed = speed - NewSpeed;
    13.     }
    14. }
    15.  
     
  27. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    mover is null. Do a null reference check before executing that statement. If mover is null, assign mover, then proceed.
     
  28. JUANCAMARGO

    JUANCAMARGO

    Joined:
    May 9, 2015
    Posts:
    10
    Can you help me please with the syntax or the coding?
     
  29. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    Code (CSharp):
    1. if(mover == null)
    2.      return;
     
  30. JUANCAMARGO

    JUANCAMARGO

    Joined:
    May 9, 2015
    Posts:
    10
    And i add that line of code in Start() or In SpawnWaves?
     
  31. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    In spawn waves, before line 43 that is returning the error. So put it on line 43 and shift line 43 down to line 44.
     
  32. JUANCAMARGO

    JUANCAMARGO

    Joined:
    May 9, 2015
    Posts:
    10
    I did it, but now i have a syntax error, it says that I need to use the yield return instruction or yield break, now if i use yield return still being a mistake because expects more instructions, and if I use yield break, after the fisrt wave the game continues but the asteroids stops.
     
  33. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    Oh, right that's in a coroutine not a normal method. I'm going to have to look a little harder.
     
  34. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    This might do the trick. I obviously didn't test this because I don't have your project:
    Code (CSharp):
    1.  
    2. IEnumerator SpawnWaves()
    3.         {
    4.             yield return new WaitForSeconds(startWait);
    5.             while (true)
    6.             {  
    7.                 if(mover != null){
    8.                     for (int i = 0; i < hazardCount; i++)
    9.                     {
    10.                         Vector3 SpawnPosition = new Vector3(Random.Range(-SpawnValues.x, SpawnValues.x), SpawnValues.y, SpawnValues.z);
    11.                         Quaternion SpawnRotation = Quaternion.identity;
    12.                         Instantiate(Hazard, SpawnPosition, SpawnRotation);
    13.                         yield return new WaitForSeconds(spawnWait);
    14.                         mover.AddSpeed(newspeed);
    15.                     }
    16.                  
    17.                     yield return new WaitForSeconds(waveWait);
    18.                 } else {
    19.                     if (objeto_mover != null)
    20.                     {
    21.                         mover = objeto_mover.GetComponent<Mover>();
    22.                     }
    23.                     yield return new WaitForEndOfFrame();
    24.                 }
    25.             }    
    26.         }
     
  35. JUANCAMARGO

    JUANCAMARGO

    Joined:
    May 9, 2015
    Posts:
    10
    I will test it. Give me a few minutes.
     
  36. JUANCAMARGO

    JUANCAMARGO

    Joined:
    May 9, 2015
    Posts:
    10
  37. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    I've not got time to debug your complete project right now as I am working on another thread. I'll be sure to take a look as soon as I get a chance, though it may not be until tomorrow. Thanks in advance for your patience!
     
    JUANCAMARGO likes this.
  38. JUANCAMARGO

    JUANCAMARGO

    Joined:
    May 9, 2015
    Posts:
    10
    No problem man!, if you can take a look, I'll really appreciate it. Take your time.
     
  39. RiokuTheSlayer

    RiokuTheSlayer

    Joined:
    Aug 22, 2013
    Posts:
    356
    Your problem:
    Code (CSharp):
    1.  StartCoroutine(SpawnWaves());
    2.         GameObject objeto_mover = GameObject.FindWithTag("Objeto");
    3.         if (objeto_mover != null)
    4.         {
    5.             mover = objeto_mover.GetComponent<Mover>();
    6.         }
    7.         if (objeto_mover == null)
    8.         {
    9.             Debug.Log("Cannot Find GameController Script");
    10.         }
    11.  
    Should actually be
    Code (CSharp):
    1.         GameObject objeto_mover = GameObject.FindWithTag("Objeto");
    2.         if (objeto_mover != null)
    3.         {
    4.             mover = objeto_mover.GetComponent<Mover>();
    5.         }
    6.         if (objeto_mover == null)
    7.         {
    8.             Debug.Log("Cannot Find GameController Script");
    9.         }
    10. StartCoroutine(SpawnWaves());
    You're starting the coroutin before you define the mover variable. Either add a delay to the coroutine at the start so it can define the value or start the coroutine after you've defined it.
     
  40. JUANCAMARGO

    JUANCAMARGO

    Joined:
    May 9, 2015
    Posts:
    10
    I'll try!
     
  41. JUANCAMARGO

    JUANCAMARGO

    Joined:
    May 9, 2015
    Posts:
    10
    I did it and still the same mistake, when I'm trying to use the metod of the mover object. This is the code.

    Code (CSharp):
    1. public class GameController : MonoBehaviour
    2. {
    3.     //Objeto para referencias a los enemigos
    4.     public GameObject Hazard;
    5.     public Vector3 SpawnValues;
    6.     public int hazardCount;
    7.     public float spawnWait;
    8.     public float startWait;
    9.     public float waveWait;
    10.     public GUIText ScoreText;
    11.     private int score, newspeed;
    12.     private Mover mover;
    13.  
    14.     void Start()
    15.     {
    16.         score = 0;
    17.         newspeed = 1;
    18.         UpdateScore();
    19.         GameObject objeto_mover = GameObject.FindWithTag("Objeto");
    20.         if (objeto_mover != null)
    21.         {
    22.             mover = objeto_mover.GetComponent<Mover>();
    23.         }
    24.         if (objeto_mover == null)
    25.         {
    26.             Debug.Log("Cannot Find GameController Script");
    27.         }      
    28.         StartCoroutine(SpawnWaves());          
    29.     }
    30.     //Spawning enemies
    31.     IEnumerator SpawnWaves()
    32.     {
    33.         yield return new WaitForSeconds(startWait);
    34.         while (true)
    35.         {
    36.             for (int i = 0; i < hazardCount; i++)
    37.                 {
    38.                     Vector3 SpawnPosition = new Vector3(Random.Range(-SpawnValues.x, SpawnValues.x), SpawnValues.y, SpawnValues.z);
    39.                     Quaternion SpawnRotation = Quaternion.identity;
    40.                     Instantiate(Hazard, SpawnPosition, SpawnRotation);
    41.                     yield return new WaitForSeconds(spawnWait);                  
    42.                 }
    43.             mover.AddSpeed(newspeed);
    44.             yield return new WaitForSeconds(waveWait);                
    45.         }      
    46.     }
    47.  
    48.     public void AddScore(int NewScoreValue)
    49.     {
    50.         score += NewScoreValue;
    51.         UpdateScore();
    52.        
    53.     }
    54.  
    55.     void UpdateScore()
    56.     {
    57.         ScoreText.text = "Score: " + score;
    58.     }
    59. }
    60.  
     
  42. OSEK_1

    OSEK_1

    Joined:
    May 16, 2014
    Posts:
    2
    Hello guys! Please I need someone to help me eith my code. I am working on a game project, and am having an issue with one of my script and couldn't figure out what the issue was.
    The aim of the script is to distroy an item called "Quest_Item" when my player enters the trigger. I have a script for the Quest_Item and I also have a dialog script for an NPC that checked if quest_Achieved or not..in othe words if the player has collected the Quest_itemGameObject which will then set quest_Achieved variable to true inside the Quest_Items script.

    This is my error merssage from the console:
    NullReferenceException: Object reference not set to an instance of an object
    O_Quest_Items.OnTriggerEnter (UnityEngine.Collider col) (at Assets/Scripts/O_Quest_Items.cs:17)


    And this is my script:
     

    Attached Files:

  43. OSEK_1

    OSEK_1

    Joined:
    May 16, 2014
    Posts:
    2
    Sorry Guys I don't know how to display the script on here. This is my first time of posting here.
     
  44. Kat_UK

    Kat_UK

    Joined:
    May 23, 2015
    Posts:
    1
    Shout out to Zaladur for giving me the answer i needed!
    I will keep an eye on my capital letters from now on.
     
  45. brianmanee

    brianmanee

    Joined:
    Aug 14, 2015
    Posts:
    1
    NullReferenceException indicates that you are trying to access member fields, or function types, on an object reference that points to null. That means the reference to an Object which is not initialized. More details withexample........NullReferenceException

    Brian
     
  46. deeps deshwal

    deeps deshwal

    Joined:
    Sep 9, 2015
    Posts:
    1
    i have tried every thing whatever has been taught on this page...nullreference error is not removing..pls help me
     
  47. KirthiKV

    KirthiKV

    Joined:
    Sep 27, 2015
    Posts:
    2
    Guys I am getting this error and have been struggling since 4 days, can you please help me with this what may be the reason. I have to submit this else I will loose the project. I am trying as I write this, please let me know if you have solved this ?? Attached is the screenshot for the Null Reference Error
     

    Attached Files:

  48. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    Check line 264 of the scripts. Something is not instantiated while you try to access it on that line.
     
  49. KirthiKV

    KirthiKV

    Joined:
    Sep 27, 2015
    Posts:
    2
    I have checked the code and found that there is no flaw in the code. Can you suggest any other remedies? I have attached the code for reference.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using UnityEngine;

    public static class PluginFunctions
    {
    [NonSerialized]
    public static bool inited = false;

    // Delegate type declaration.
    public delegate void LogCallback([MarshalAs(UnmanagedType.LPStr)] string msg);

    // Delegate instance.
    private static LogCallback logCallback = null;
    private static GCHandle logCallbackGCH;

    public static void arwRegisterLogCallback(LogCallback lcb)
    {
    if (lcb != null) {
    logCallback = lcb;
    logCallbackGCH = GCHandle.Alloc(logCallback); // Does not need to be pinned, see http://stackoverflow.com/a/19866119/316487
    }
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwRegisterLogCallback(logCallback);
    else ARNativePlugin.arwRegisterLogCallback(logCallback);
    if (lcb == null) {
    logCallback = null;
    logCallbackGCH.Free();
    }
    }

    public static bool arwInitialiseAR(int pattSize = 16, int pattCountMax = 25)
    {
    bool ok;
    if (Application.platform == RuntimePlatform.IPhonePlayer) ok = ARNativePluginStatic.arwInitialiseARWithOptions(pattSize, pattCountMax);
    else ok = ARNativePlugin.arwInitialiseARWithOptions(pattSize, pattCountMax);
    if (ok) PluginFunctions.inited = true;
    return ok;
    }

    public static string arwGetARToolKitVersion()
    {
    StringBuilder sb = new StringBuilder(128);
    bool ok;
    if (Application.platform == RuntimePlatform.IPhonePlayer) ok = ARNativePluginStatic.arwGetARToolKitVersion(sb, sb.Capacity);
    else ok = ARNativePlugin.arwGetARToolKitVersion(sb, sb.Capacity);
    if (ok) return sb.ToString();
    else return "unknown";
    }

    public static int arwGetError()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetError();
    else return ARNativePlugin.arwGetError();
    }

    public static bool arwShutdownAR()
    {
    bool ok;
    if (Application.platform == RuntimePlatform.IPhonePlayer) ok = ARNativePluginStatic.arwShutdownAR();
    else ok = ARNativePlugin.arwShutdownAR();
    if (ok) PluginFunctions.inited = false;
    return ok;
    }

    public static bool arwStartRunningB(string vconf, byte[] cparaBuff, int cparaBuffLen, float nearPlane, float farPlane)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwStartRunningB(vconf, cparaBuff, cparaBuffLen, nearPlane, farPlane);
    else return ARNativePlugin.arwStartRunningB(vconf, cparaBuff, cparaBuffLen, nearPlane, farPlane); // This is the error line which is being displayed.
    }

    public static bool arwStartRunningStereoB(string vconfL, byte[] cparaBuffL, int cparaBuffLenL, string vconfR, byte[] cparaBuffR, int cparaBuffLenR, byte[] transL2RBuff, int transL2RBuffLen, float nearPlane, float farPlane)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwStartRunningStereoB(vconfL, cparaBuffL, cparaBuffLenL, vconfR, cparaBuffR, cparaBuffLenR, transL2RBuff, transL2RBuffLen, nearPlane, farPlane);
    else return ARNativePlugin.arwStartRunningStereoB(vconfL, cparaBuffL, cparaBuffLenL, vconfR, cparaBuffR, cparaBuffLenR, transL2RBuff, transL2RBuffLen, nearPlane, farPlane);
    }

    public static bool arwIsRunning()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwIsRunning();
    else return ARNativePlugin.arwIsRunning();
    }

    public static bool arwStopRunning()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwStopRunning();
    else return ARNativePlugin.arwStopRunning();
    }

    public static bool arwGetProjectionMatrix(float[] matrix)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetProjectionMatrix(matrix);
    else return ARNativePlugin.arwGetProjectionMatrix(matrix);
    }

    public static bool arwGetProjectionMatrixStereo(float[] matrixL, float[] matrixR)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetProjectionMatrixStereo(matrixL, matrixR);
    else return ARNativePlugin.arwGetProjectionMatrixStereo(matrixL, matrixR);
    }

    public static bool arwGetVideoParams(out int width, out int height, out int pixelSize, out String pixelFormatString)
    {
    StringBuilder sb = new StringBuilder(128);
    bool ok;
    if (Application.platform == RuntimePlatform.IPhonePlayer) ok = ARNativePluginStatic.arwGetVideoParams(out width, out height, out pixelSize, sb, sb.Capacity);
    else ok = ARNativePlugin.arwGetVideoParams(out width, out height, out pixelSize, sb, sb.Capacity);
    if (!ok) pixelFormatString = "";
    else pixelFormatString = sb.ToString();
    return ok;
    }

    public static bool arwGetVideoParamsStereo(out int widthL, out int heightL, out int pixelSizeL, out String pixelFormatL, out int widthR, out int heightR, out int pixelSizeR, out String pixelFormatR)
    {
    StringBuilder sbL = new StringBuilder(128);
    StringBuilder sbR = new StringBuilder(128);
    bool ok;
    if (Application.platform == RuntimePlatform.IPhonePlayer) ok = ARNativePluginStatic.arwGetVideoParamsStereo(out widthL, out heightL, out pixelSizeL, sbL, sbL.Capacity, out widthR, out heightR, out pixelSizeR, sbR, sbR.Capacity);
    else ok = ARNativePlugin.arwGetVideoParamsStereo(out widthL, out heightL, out pixelSizeL, sbL, sbL.Capacity, out widthR, out heightR, out pixelSizeR, sbR, sbR.Capacity);
    if (!ok) {
    pixelFormatL = "";
    pixelFormatR = "";
    } else {
    pixelFormatL = sbL.ToString();
    pixelFormatR = sbR.ToString();
    }
    return ok;
    }

    public static bool arwCapture()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwCapture();
    else return ARNativePlugin.arwCapture();
    }

    public static bool arwUpdateAR()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwUpdateAR();
    else return ARNativePlugin.arwUpdateAR();
    }

    public static bool arwUpdateTexture([In, Out]Color[] colors)
    {
    bool ok;
    GCHandle handle = GCHandle.Alloc(colors, GCHandleType.Pinned);
    IntPtr address = handle.AddrOfPinnedObject();
    if (Application.platform == RuntimePlatform.IPhonePlayer) ok = ARNativePluginStatic.arwUpdateTexture(address);
    else ok = ARNativePlugin.arwUpdateTexture(address);
    handle.Free();
    return ok;
    }

    public static bool arwUpdateTextureStereo([In, Out]Color[] colorsL, [In, Out]Color[] colorsR)
    {
    bool ok;
    GCHandle handle0 = GCHandle.Alloc(colorsL, GCHandleType.Pinned);
    GCHandle handle1 = GCHandle.Alloc(colorsR, GCHandleType.Pinned);
    IntPtr address0 = handle0.AddrOfPinnedObject();
    IntPtr address1 = handle1.AddrOfPinnedObject();
    if (Application.platform == RuntimePlatform.IPhonePlayer) ok = ARNativePluginStatic.arwUpdateTextureStereo(address0, address1);
    else ok = ARNativePlugin.arwUpdateTextureStereo(address0, address1);
    handle0.Free();
    handle1.Free();
    return ok;
    }

    public static bool arwUpdateTexture32([In, Out]Color32[] colors32)
    {
    bool ok;
    GCHandle handle = GCHandle.Alloc(colors32, GCHandleType.Pinned);
    IntPtr address = handle.AddrOfPinnedObject();
    if (Application.platform == RuntimePlatform.IPhonePlayer) ok = ARNativePluginStatic.arwUpdateTexture32(address);
    else ok = ARNativePlugin.arwUpdateTexture32(address);
    handle.Free();
    return ok;
    }

    public static bool arwUpdateTexture32Stereo([In, Out]Color32[] colors32L, [In, Out]Color32[] colors32R)
    {
    bool ok;
    GCHandle handle0 = GCHandle.Alloc(colors32L, GCHandleType.Pinned);
    GCHandle handle1 = GCHandle.Alloc(colors32R, GCHandleType.Pinned);
    IntPtr address0 = handle0.AddrOfPinnedObject();
    IntPtr address1 = handle1.AddrOfPinnedObject();
    if (Application.platform == RuntimePlatform.IPhonePlayer) ok = ARNativePluginStatic.arwUpdateTexture32Stereo(address0, address1);
    else ok = ARNativePlugin.arwUpdateTexture32Stereo(address0, address1);
    handle0.Free();
    handle1.Free();
    return ok;
    }

    public static bool arwUpdateTextureGL(int textureID)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwUpdateTextureGL(textureID);
    else return ARNativePlugin.arwUpdateTextureGL(textureID);
    }

    public static bool arwUpdateTextureGLStereo(int textureID_L, int textureID_R)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwUpdateTextureGLStereo(textureID_L, textureID_R);
    else return ARNativePlugin.arwUpdateTextureGLStereo(textureID_L, textureID_R);
    }

    public static void arwSetUnityRenderEventUpdateTextureGLTextureID(int textureID)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetUnityRenderEventUpdateTextureGLTextureID(textureID);
    else ARNativePlugin.arwSetUnityRenderEventUpdateTextureGLTextureID(textureID);
    }

    public static void arwSetUnityRenderEventUpdateTextureGLStereoTextureIDs(int textureID_L, int textureID_R)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetUnityRenderEventUpdateTextureGLStereoTextureIDs(textureID_L, textureID_R);
    else ARNativePlugin.arwSetUnityRenderEventUpdateTextureGLStereoTextureIDs(textureID_L, textureID_R);
    }

    public static int arwGetMarkerPatternCount(int markerID)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetMarkerPatternCount(markerID);
    else return ARNativePlugin.arwGetMarkerPatternCount(markerID);
    }

    public static bool arwGetMarkerPatternConfig(int markerID, int patternID, float[] matrix, out float width, out float height, out int imageSizeX, out int imageSizeY)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetMarkerPatternConfig(markerID, patternID, matrix, out width, out height, out imageSizeX, out imageSizeY);
    else return ARNativePlugin.arwGetMarkerPatternConfig(markerID, patternID, matrix, out width, out height, out imageSizeX, out imageSizeY);
    }

    public static bool arwGetMarkerPatternImage(int markerID, int patternID, [In, Out]Color[] colors)
    {
    bool ok;
    if (Application.platform == RuntimePlatform.IPhonePlayer) ok = ARNativePluginStatic.arwGetMarkerPatternImage(markerID, patternID, colors);
    else ok = ARNativePlugin.arwGetMarkerPatternImage(markerID, patternID, colors);
    return ok;
    }

    public static bool arwGetMarkerOptionBool(int markerID, int option)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetMarkerOptionBool(markerID, option);
    else return ARNativePlugin.arwGetMarkerOptionBool(markerID, option);
    }

    public static void arwSetMarkerOptionBool(int markerID, int option, bool value)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetMarkerOptionBool(markerID, option, value);
    else ARNativePlugin.arwSetMarkerOptionBool(markerID, option, value);
    }

    public static int arwGetMarkerOptionInt(int markerID, int option)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetMarkerOptionInt(markerID, option);
    else return ARNativePlugin.arwGetMarkerOptionInt(markerID, option);
    }

    public static void arwSetMarkerOptionInt(int markerID, int option, int value)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetMarkerOptionInt(markerID, option, value);
    else ARNativePlugin.arwSetMarkerOptionInt(markerID, option, value);
    }

    public static float arwGetMarkerOptionFloat(int markerID, int option)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetMarkerOptionFloat(markerID, option);
    else return ARNativePlugin.arwGetMarkerOptionFloat(markerID, option);
    }

    public static void arwSetMarkerOptionFloat(int markerID, int option, float value)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetMarkerOptionFloat(markerID, option, value);
    else ARNativePlugin.arwSetMarkerOptionFloat(markerID, option, value);
    }

    public static void arwSetVideoDebugMode(bool debug)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetVideoDebugMode(debug);
    else ARNativePlugin.arwSetVideoDebugMode(debug);
    }

    public static bool arwGetVideoDebugMode()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetVideoDebugMode();
    else return ARNativePlugin.arwGetVideoDebugMode();
    }

    public static void arwSetVideoThreshold(int threshold)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetVideoThreshold(threshold);
    else ARNativePlugin.arwSetVideoThreshold(threshold);
    }

    public static int arwGetVideoThreshold()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetVideoThreshold();
    else return ARNativePlugin.arwGetVideoThreshold();
    }

    public static void arwSetVideoThresholdMode(int mode)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetVideoThresholdMode(mode);
    else ARNativePlugin.arwSetVideoThresholdMode(mode);
    }

    public static int arwGetVideoThresholdMode()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetVideoThresholdMode();
    else return ARNativePlugin.arwGetVideoThresholdMode();
    }

    public static void arwSetLabelingMode(int mode)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetLabelingMode(mode);
    else ARNativePlugin.arwSetLabelingMode(mode);
    }

    public static int arwGetLabelingMode()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetLabelingMode();
    else return ARNativePlugin.arwGetLabelingMode();
    }

    public static void arwSetBorderSize(float size)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetBorderSize(size);
    else ARNativePlugin.arwSetBorderSize(size);
    }

    public static float arwGetBorderSize()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetBorderSize();
    else return ARNativePlugin.arwGetBorderSize();
    }

    public static void arwSetPatternDetectionMode(int mode)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetPatternDetectionMode(mode);
    else ARNativePlugin.arwSetPatternDetectionMode(mode);
    }

    public static int arwGetPatternDetectionMode()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetPatternDetectionMode();
    else return ARNativePlugin.arwGetPatternDetectionMode();
    }

    public static void arwSetMatrixCodeType(int type)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetMatrixCodeType(type);
    else ARNativePlugin.arwSetMatrixCodeType(type);
    }

    public static int arwGetMatrixCodeType()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetMatrixCodeType();
    else return ARNativePlugin.arwGetMatrixCodeType();
    }

    public static void arwSetImageProcMode(int mode)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetImageProcMode(mode);
    else ARNativePlugin.arwSetImageProcMode(mode);
    }

    public static int arwGetImageProcMode()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetImageProcMode();
    else return ARNativePlugin.arwGetImageProcMode();
    }

    public static void arwSetNFTMultiMode(bool on)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) ARNativePluginStatic.arwSetNFTMultiMode(on);
    else ARNativePlugin.arwSetNFTMultiMode(on);
    }

    public static bool arwGetNFTMultiMode()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwGetNFTMultiMode();
    else return ARNativePlugin.arwGetNFTMultiMode();
    }


    public static int arwAddMarker(string cfg)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwAddMarker(cfg);
    else return ARNativePlugin.arwAddMarker(cfg);
    }

    public static bool arwRemoveMarker(int markerID)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwRemoveMarker(markerID);
    else return ARNativePlugin.arwRemoveMarker(markerID);
    }

    public static int arwRemoveAllMarkers()
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwRemoveAllMarkers();
    else return ARNativePlugin.arwRemoveAllMarkers();
    }


    public static bool arwQueryMarkerVisibility(int markerID)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwQueryMarkerVisibility(markerID);
    else return ARNativePlugin.arwQueryMarkerVisibility(markerID);
    }

    public static bool arwQueryMarkerTransformation(int markerID, float[] matrix)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwQueryMarkerTransformation(markerID, matrix);
    else return ARNativePlugin.arwQueryMarkerTransformation(markerID, matrix);
    }

    public static bool arwQueryMarkerTransformationStereo(int markerID, float[] matrixL, float[] matrixR)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwQueryMarkerTransformationStereo(markerID, matrixL, matrixR);
    else return ARNativePlugin.arwQueryMarkerTransformationStereo(markerID, matrixL, matrixR);
    }

    public static bool arwLoadOpticalParams(string optical_param_name, byte[] optical_param_buff, int optical_param_buffLen, out float fovy_p, out float aspect_p, float[] m, float[] p)
    {
    if (Application.platform == RuntimePlatform.IPhonePlayer) return ARNativePluginStatic.arwLoadOpticalParams(optical_param_name, optical_param_buff, optical_param_buffLen, out fovy_p, out aspect_p, m, p);
    else return ARNativePlugin.arwLoadOpticalParams(optical_param_name, optical_param_buff, optical_param_buffLen, out fovy_p, out aspect_p, m, p);
    }

    }
     
  50. King_Chaos

    King_Chaos

    Joined:
    Nov 5, 2015
    Posts:
    1
    I am having the same problem with movement on my player.

    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    public float speed;

    private Rigidbody rb;
    void start()
    {
    rb = GetComponent<Rigidbody>();
    }

    void FixedUpdate()
    {
    float moveHorizonal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");
    Vector3 movement = new Vector3(moveHorizonal, 0.0f, moveVertical);
    rb.velocity = movement * speed;
    }
    }
     
Thread Status:
Not open for further replies.