Quantcast
Channel: Questions in topic: "nullreferenceexception"
Viewing all 1530 articles
Browse latest View live

random occuring NullReferenceException

$
0
0
I have the following problem: My game throws me follwing error at a random occuring basis. I have not found any pattern in it or anything. When I start the game and try to interact with an object sometimes the error pops up. If not the game runs smooth till the finish. I'm quite helpless with it. Has anyone an Idea? NullReferenceException at (wrapper managed-to-native) UnityEngine.Behaviour:get_isActiveAndEnabled () at UnityEngine.EventSystems.UIBehaviour.IsActive () [0x00002] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\UIBehaviour.cs:22 at UnityEngine.UI.Graphic.SetVerticesDirty () [0x00002] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\UI\Core\Graphic.cs:100 at UnityEngine.UI.Text.set_text (System.String value) [0x00053] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\UI\Core\Text.cs:138 at Score.AddToScore1 (Int32 i, System.String name) [0x000ff] in D:\Unity\TauchroboterSpiel_25_04\Assets\Scripts\Score.cs:43 at Collectable.OnEndDrag (UnityEngine.EventSystems.PointerEventData eventData) [0x00188] in D:\Unity\TauchroboterSpiel_25_04\Assets\Scripts\Collectable.cs:166 at UnityEngine.EventSystems.ExecuteEvents.Execute (IEndDragHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00008] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:80 at UnityEngine.EventSystems.ExecuteEvents.Execute[IEndDragHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00073] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:269 UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object) UnityEngine.DebugLogHandler:LogException(Exception, Object) UnityEngine.Logger:LogException(Exception, Object) UnityEngine.Debug:LogException(Exception) UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:273) UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean) (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:302) UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:200) UnityEngine.EventSystems.StandaloneInputModule:Process() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:183) UnityEngine.EventSystems.EventSystem:Update() (at C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\EventSystem.cs:287) Here the related part of the Code (it's a MonoBehaviour): public int score1 = 0; public int score2 = 0; public Text txtscore1, txtscore2; List collected1 = new List(); List collected2 = new List(); public OnScreenText onScreenText; void Start(){ onScreenText = GameObject.Find("GlobalController").GetComponent(); } void Awake() { DontDestroyOnLoad(transform.gameObject); } public void AddToScore1(int i, string name){ if(collected1.Count > 0){ bool add = true; foreach(string s in collected1){ if(s == name){ add = false; } } if(add){ collected1.Add(name); score1 += i; txtscore1.text = "" + score1; onScreenText.DisplayText("+"+i,1f,1); } }else{ collected1.Add(name); score1 += i; txtscore1.text = "" + score1; onScreenText.DisplayText("+"+i,1f,1); } }

Object not responding to OnTriggerEnter()

$
0
0
So I'm trying to get a car to respawn at a general location some short time after passing a collider. For some reason, the script works if I walk into the collider with FirstPersonController. However it won't affect the car. Interestingly, if I test carReset() with "p" as shown in Update() after the car passes the collider, I get the error: "NullReferenceException: Object reference not set to an instance of an object". I'm fairly new to scripting and unity and I can't figure out why this wouldn't be working but still affects FirstPersonController. Here's the script: public class CarRespawn : MonoBehaviour { GameObject car; void Update(){ if (Input.GetKeyDown ("p")) { carReset (); } } void OnTriggerEnter(Collider c_car){ car = c_car.gameObject; Invoke ("carReset", Random.Range (0.5f, 3.0f)); } void carReset(){ car.transform.position = new Vector3 (Random.Range (-6.0f, -12.0f), 1.16f, Random.Range(25.0f, 60.0f) ); } }

Change parameter in a component of a GameObject after instantiating it with PUN

$
0
0
Hello, I'v been trying to instantiate two GameObjects with PUN. I have a script for the first character that must contain the second character that was also instantiated to the scene (will not do what it supposed to do with the prefab itself, only with the instantiated one). First, I instantiated the gameObject: GameObject characterInstantiate1 = PhotonNetwork.Instantiate (characterPrefabName1, spawnPoint1.position, spawnPoint1.rotation, 0); GameObject characterInstantiate2 = PhotonNetwork.Instantiate (characterPrefabName2, spawnPoint2.position, spawnPoint2.rotation, 0); Then, I tried accessing to the GameObject's component: characterInstantiate1.GetComponent ().publicParameter = characterInstantiate2.transform; But I'm getting the error : "NullReferenceException: Object reference not set to an instance of an object"..

Tanks Tutorial: Accessing TankHealth

$
0
0
I've been trying to expand on the Tanks tutorial, which involves passing each tank's current health on to a script controlling audio (Hv_Sine440_HvParam_AudioLib). I'm afraid I'm pretty new to Unity so I've had to battle through a lot of errors. The latest of these comes in line 35 - print(tankHealth[0].m_StartingHealth); - which gives me a NullReferenceException. Would anyone familiar with the tutorial be able to explain why it's not working? Any help would be much appreciated. The only thing I've changed elsewhere is moving SpawnAllTanks() in the GameManager script from Start() to Awake(). using System.Collections; using System.Collections.Generic; using UnityEngine; public class Hv_Sine_Control : MonoBehaviour { private Complete.GameManager gameManager; private Complete.TankHealth[] tankHealth; private GameObject[] tanks; private Hv_Sine440_HvParam_AudioLib hv; public float freq; void Awake () { gameManager = GetComponent(); print (gameManager.m_Tanks.Length); tankHealth = new Complete.TankHealth[gameManager.m_Tanks.Length]; } void Start () { hv = GetComponent(); // Get and set a parameter freq = hv.GetFloatParameter(Hv_Sine440_HvParam_AudioLib.Parameter.Freq); //hv.SetFloatParameter(Hv_Sine440_HvParam_AudioLib.Parameter.Freq, freq + 0.1f); Debug.Log(gameManager.m_Tanks.Length); print (gameManager.m_Tanks[0].m_PlayerNumber); for (int i = 0; i < gameManager.m_Tanks.Length; i++) { tankHealth[i] = gameManager.m_Tanks[i].m_Instance.GetComponent(); } print(tankHealth[0].m_StartingHealth); //Check to see if tankHealth[] is set up properly. } void Update () { //hv.SetFloatParameter (Hv_Sine440_HvParam_AudioLib.Parameter.Freq, freq + (playerController.count * (440 / 12))); //hv.SetFloatParameter(Hv_Sine440_HvParam_AudioLib.Parameter.Freq, freq++); //hv.SetFloatParameter(Hv_Sine440_HvParam_AudioLib.Parameter.Freq, tankHealth[1].m_Slider.value + 300f); } }

Adding and removing specific components to a list based OnTriggerEnter/Exit, Getting Null Exceptions

$
0
0
Here's the code in question: void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.GetComponentInParent()) { r = other.gameObject.GetComponentInParent(); camGoto = true; if (!colList.Contains(other)) colList.Add(other); } } void OnTriggerExit2D(Collider2D other) { if (other.gameObject.GetComponentInParent()) { if (colList.Contains(other)) colList.Remove(other); } } Upon starting the game I get a bunch of "NullReferenceException: Object reference not set to an instance of an object PlayerController.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/PlayerController.cs:63)" (presumably because those objects didn't get their parent set yet?). When I collide with something else (in my case another player, only without the controller script) I get those errors again, also for the Exit this time. Any explanation why this is happening/how to fix it? Everything seems to work despite the errors but it doesn't feel right just letting them be.

NullReferenceException was thrown when raise an event

$
0
0
I want to implement the communication between GameObjects via Event. But a NullReferenceException was thrown when raise an event. public class PathController : MonoBehaviour { public event EventHandler FileSended; void Start() { ...... try { //Copy the file. File.Copy(path, destpath, true); if (FileSended != null) { FileSended(this, EventArgs.Empty);//Throw an Exception } } catch (Exception ex) { Debug.LogError(ex.ToString()); } ...... } } The component above is attached to Empty GameObject PathController. The component belowis attached to Empty GameObject SerialController. Both GameObjects are on the same scene. public class SerialController : MonoBehaviour { void Awake() { SerialIni.LoadSerialIni();//加载ini设置 GameObject.Find("PathController").GetComponent().FileSended += OnFileSended; } // Use this for initialization void Start() { ...... //GameObject.Find("PathController").GetComponent().FileSended += OnFileSended; ...... } } When I subscribe the event on Awake(), it will throw an exception. The exception information is below: System.NullReferenceException: Object reference not set to an instance of an object at SerialController .OnFileSended (System.Object sender) [0x00007] in C:\Users\MyPC\Desktop\MyGame\Assets\Scripts\SerialController .cs:402 at PathController+c__Iterator1.MoveNext () [0x0007b] in C:\Users\MyPC\Desktop\MyGame\Assets\Scripts\PathController.cs:118 When I subscribe the event on Start(), it will NOT throw an exception.But the function OnFileSended(object sender, EventArgs e)(as showed below) will never run. public void OnFileSended(object sender, EventArgs e) { if (sp.IsOpen) { byteForWrite[0] = CODEFILE; sp.Write(byteForWrite, 0, 1); } } How can i do to Fix it?It would be great if someone could help me.

MergeSort function acting strange

$
0
0
Hello (again) all! I'm having a strange issue with my script. In this script, I sort an Array of RawImages using the corresponding Location (an original class including just row, column, and height). However, every time I run the program, the very first location in the Location array is always set to null, and it's only found to be null within the DoMerge method. This is the MergeSort algorithm I'm using and the method in which I'm using it. L: public void MergeSort_Recursive (RawImage[] imgs, Location[] locs, int left, int right) { print ("Merge sorting list of length " + locs.Length + " from " + left + " to " + right); int mid; if (right > left) { mid = (right + left) / 2; if (locs [0] == null) { throw new NullReferenceException ("NULL AT " + 0); } else { print ("0 LOC " + locs.Length + "IS " + locs [0]); MergeSort_Recursive(imgs, locs, left, mid); MergeSort_Recursive(imgs, locs, (mid + 1), right); DoMerge(imgs, locs, left, (mid + 1), right); } } } public void DoMerge(RawImage[] imgs, Location[] locs, int left, int mid, int right) { if (locs [0] == null) { throw new NullReferenceException ("NULL AT " + 0); } RawImage[] temp = new RawImage [25]; Location [] tempLocs = new Location[25]; int i, left_end, num_elements, tmp_pos; left_end = (mid - 1); tmp_pos = left; num_elements = (right - left + 1); while ((left <= left_end) && (mid <= right)) { if (locs [left] == null) { for (int p = 0; p < locs.Length; p ++) { print (locs [p]); throw new NullReferenceException ("locs [" + left + "] is null"); } } if (locs [left].Row <= locs [mid].Row) { temp [tmp_pos++] = imgs [left++]; tempLocs [tmp_pos++] = locs [left++]; } else { temp [tmp_pos++] = imgs [mid++]; tempLocs [tmp_pos++] = locs [mid++]; } } while (left <= left_end) { temp [tmp_pos++] = imgs [left++]; tempLocs [tmp_pos++] = locs [left++]; } while (mid <= right) { temp [tmp_pos++] = imgs [mid++]; tempLocs [tmp_pos++] = locs [mid++]; } for (i = 0; i < num_elements; i++) { imgs[right] = temp[right]; locs [right] = tempLocs [right]; right--; } } public void sortAllObjects () { ArrayList allObs = new ArrayList (); ArrayList allLocs = new ArrayList (); ArrayList tiles = new ArrayList (), tileLocs = new ArrayList (); Location loc, lastLoc = null; RawImage img; for (int i = 0; i < battleMap.Roster.Count; i++) { if (((Player)battleMap.Roster [i]).currentLocation () != null) { allObs.Add (((Player)battleMap.Roster [i]).MapSprite); allLocs.Add (((Player)battleMap.Roster [i]).currentLocation ()); } } if (allLocs [0] == null) { throw new NullReferenceException ("DAFUQ?! COME ON MAN!"); } for (int i = 0; i < miniMap.Length; i++) { for (int j = 0; j < miniMap [0].Length; j++) { loc = new Location (i, j); if (battleMap.heightOf (loc) > 0) { tiles.Add (tileMap [i] [j]); tileLocs.Add (new Location (i, j)); } if (!battleMap.isEmpty (loc) && !battleMap.objectAt (loc).sentient ()) { allObs.Add (miniMap [i] [j]); allLocs.Add (new Location (i, j)); } if (!battleMap.isEmptyBenign (loc) || !battleMap.isEmptyInteractable (loc)) { allObs.Add (interMap [i] [j]); allLocs.Add (new Location (i, j)); } } } RawImage[] imgs = new RawImage[allObs.Count]; Location[] locs = new Location[imgs.Length]; for (int i = 0; i < imgs.Length; i++) { imgs [i] = (RawImage)allObs [i]; locs [i] = (Location)allLocs [i]; } if (locs [0] == null) { throw new NullReferenceException ("NULL AT " + 0); } MergeSort_Recursive (imgs, locs, 0, imgs.Length - 1); for (int i = 0; i < imgs.Length; i++) { imgs [i].transform.SetAsFirstSibling (); } imgs = new RawImage[tiles.Count]; locs = new Location[imgs.Length]; for (int i = 0; i < imgs.Length; i++) { imgs [i] = (RawImage)tiles [i]; locs [i] = (Location)tileLocs [i]; } MergeSort_Recursive (imgs, locs, 0, imgs.Length - 1); for (int i = 0; i < imgs.Length; i++) { imgs [i].transform.SetAsFirstSibling (); } for (int i = 0; i < allLocs.Count; i++) { ((RawImage)allObs [i]).transform.SetAsFirstSibling (); } for (int i = 0; i < tiles.Count; i++) { ((RawImage)tiles [i]).transform.SetAsFirstSibling (); } groundTexture.transform.SetAsFirstSibling (); } I'm having zero issues with the other parts, but as soon as I run the program... ![alt text][1] [1]: /storage/temp/93512-mergesort-3.png

Return value inexplicably becomes null

$
0
0
The following function gives me null whenever I call it. private Avatar GetAvatar() { List party = GameObject.FindObjectOfType ().GetAvatarsInParty (); foreach (Avatar avatar in party) { if (avatar.name.Contains ("AvatarName")) { print(avatar); return avatar; } } return null; } It's definitely hitting *return avatar*, and *print(avatar)* is successfully printing the name of the FieldAvatar I want. The only explanation is that I'm an idiot and that I don't understand something basic about how this is meant to work.

NullRerefanceException. Cant access other scripts variable!!

$
0
0
Hello guys. I've been going crazy, I want to AICharactercontroller standart script to run towards main character when Pick up object is picked up. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.AI; public class PlayerController : MonoBehaviour { public float speed; public Text countText; public Text winText; UnityStandardAssets.Characters.ThirdPerson.AICharacterControl PoliceRun; GameObject Winston; private GameObject police; public int count; private Rigidbody rb; Transform target1; private Vector3 place; // Use this for initialization void Start() { rb = GetComponent(); count = 0; SetCountText(); winText.text = ""; police = GameObject.FindWithTag("Winston"); PoliceRun = police.GetComponent(); target1 = GameObject.FindWithTag("Winston").GetComponent(); } // Update is called once per frame void Update() { } private void FixedUpdate() { } void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Pick Up")) ; { other.gameObject.SetActive(false); count = count + 1; SetCountText(); target1 = PoliceRun.target; } } void SetCountText() { countText.text = "Collected=" + count.ToString(); if (count >= 12 ) { winText.text = "WIN!"; } } } NullReferenceException: Object reference not set to an instance of an object PlayerController.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/PlayerController.cs:50) I get this error. What can be done for this purpose?

I'm going nuts for 2 days about NullReferenceException error please help!

$
0
0
Hello guys. My main character will pick an object "Pick ups" and Police will chase him(AIThirdpersonController). I couln't do it no matter what. Plase take a look at my codes. I'm trying to acces a function from another one. Thank you Thats my PlayerController script on my main character(Wilson); using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.AI; using UnityStandardAssets.Characters.ThirdPerson; public class PlayerController : MonoBehaviour { public float speed; public Text countText; public Text winText; AICharacterControl PoliceRun; GameObject Winston; private GameObject police; public int count; private Rigidbody rb; Transform target; private Vector3 place; string count1; // Use this for initialization void Start() { rb = GetComponent(); count = 0; SetCountText(); winText.text = ""; police = GameObject.FindWithTag("Police"); Winston = GameObject.FindWithTag("Winston"); PoliceRun = GameObject.FindWithTag("Police").GetComponent(); Debug.Log(target.ToString()); } // Update is called once per frame void Update() { } private void FixedUpdate() { } void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Pick Up")) ; { other.gameObject.SetActive(false); count = count + 1; SetTargetAI(); } } void SetCountText() { count1 = countText.text; countText.text = "Collected=" + count.ToString(); if (count >= 12 ) { winText.text = "WIN!"; } } void SetTargetAI() { PoliceRun.SetTarget(Winston.transform); } } And Thats AICharacterControl (police) ; using System; using UnityEngine; using UnityStandardAssets.Characters.ThirdPerson namespace UnityStandardAssets.Characters.ThirdPerson { [RequireComponent(typeof(UnityEngine.AI.NavMeshAgent))] [RequireComponent(typeof(ThirdPersonCharacter))] public class AICharacterControl : MonoBehaviour { public UnityEngine.AI.NavMeshAgent agent { get; private set; } // the navmesh agent required for the path finding public ThirdPersonCharacter character { get; private set; } // the character we are controlling public Transform target; // target to aim for PlayerController pc; Transform WinstonT; private void Start() { // get the components on the object we need ( should not be null due to require component so no need to check ) agent = GetComponentInChildren(); character = GetComponent(); agent.updateRotation = false; agent.updatePosition = true; pc = GameObject.FindWithTag("Police").GetComponent(); WinstonT = GameObject.FindWithTag("Winston").transform; } private void Update() { if (target != null) agent.SetDestination(target.position); if (agent.remainingDistance > agent.stoppingDistance) character.Move(agent.desiredVelocity, false, false); else character.Move(Vector3.zero, false, false); } public void SetTarget(Transform target) { this.target = target; } } } I'm getting this error. NullReferenceException: Object reference not set to an instance of an object PlayerController.SetTargetAI () (at Assets/Scripts/PlayerController.cs:74) PlayerController.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/PlayerController.cs:53

JSONUtilities returning null

$
0
0
I am getting irritated at the JsonUtilities.FromJson(string data) thing. I pass it a working string and it just returns null causing everything to break. The problem is, it worked before and I didn't change anything. Here is the method that it's in: public void LoadData() { if( File.Exists(dataPath) ) { string jsonFileData = File.ReadAllText( dataPath ); print( jsonFileData ); if( jsonFileData.Equals( "" ) ) { return; } Settings colorSettings = JsonUtility.FromJson( jsonFileData ); for(int i = 0; i < colorSettings.items.Length; i++ ) { Color tempColor = new Color(); if( ColorUtility.TryParseHtmlString( colorSettings.items[i].value, out tempColor ) ) { throw new System.Exception( "Unable to parse hex to color." ); } colorPref.Add( colorSettings.items[i].key, tempColor ); } } } Any idea as to why it won't work anymore? Cuz I have no idea as to why it stopped working. I'm using Unity 5.6.

Why Am I Getting Null Reference Exception?

$
0
0
I don't get it. I want it to check if it finds a collider with the tag Lootable. What am I missing here? I'm so confused :\ private void FixedUpdate() { mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit rayHit; if (Input.GetButtonDown("Fire1")) { Physics.Raycast(mouseRay, out rayHit); if (rayHit.collider.tag.Equals("Lootable")) { print("hit"); print(inventoryWindowShow); inventoryWindowShow = true; } } if (Input.GetKeyDown(KeyCode.Escape)) { inventoryWindowShow = false; } }

(javascript) object refrence not set to an instance of an object

$
0
0
whenever i hit the play button i receive an error that says NullReferenceException: Object reference not set to an instance of an object dovemoveup.Update () (at Assets/dovemoveup.js:11) this is the script var timer : Countdown; var anim : Animator; function Start () { anim = GetComponent("Animator"); } function Update () { if(timer.time <= 0f); { anim.SetBool("open",true); } }

Space Shooter - NullReferenceException on Scene Reload

$
0
0
I'd like to get help on understanding the issue I'm having with Space Shooter tutorial. It was completed fully completed and on initial scene load works perfectly. But on restarting the scene the game is loosing number of objects with NullReferenceExpection raised on line GameObject hazard = hazards[Random.Range(0, hazards.Length)]; Initial Background and Player objects still works, including sounds and Bolt, but following objects are not visible from the scene hierarchy: -Starfield - completely gone -Second Background (scrolling stopping to work) -Game Controller Hazards: Size becomes 0 and references to all Elements are gone. On full game restart all the missing object reappearing (as per project) and gone again on the scene restart. The _Complete_Game works perfectly. The scripts are fully compared and all visual issues are checked. Google hints on Awake() and etc. didn't help. I think it's important to understand the issue before continue exploring Unity. I'd appreciate any idea.

NullReferenceExeption when I use Mask

$
0
0
I am trying to make a Mask, but when I click the Play button i get this error. How can I fix it? ![alt text][1] [1]: /storage/temp/94838-94801-3.png

NullReferenceException: Object reference not set to an instance of an object ProgressBar.Start ()

$
0
0
Hello. So I am trying to make an Idle game and I'm just experimenting with the progress bar stuff. So what I'm trying to do is make the progress bar autofill to 100% and every time it does that, my population gains by 1. I got the progress bar to work and auto reset but I'm struggling to pull the "population" variable from my "Population" script. I am making the progress bar in the "Progress Bar" script. But I get the error NullReferenceException: Object reference not set to an instance of an object ProgressBar.Start () (at Assets/Scripts/ProgressBar.cs:21) and I haven't found anything during over 30 minutes of search. Here are the scripts below if you guys have any ideas. Population using System.Collections; using System.Collections.Generic; using UnityEngine; public class Population : MonoBehaviour { public UnityEngine.UI.Text populationText; public UnityEngine.UI.Text ppc; public UnityEngine.UI.Button summon; public float population = 0f; public float populationPerClick; // Large Number Variables /* void Update() { // Plurals // Population Total if (population == 1) { populationText.text = population + " human on Earth"; } else if (population == 0) { populationText.text = population + " humans on Earth"; } else if (population > 1) { populationText.text = population + " humans on Earth"; } // Humans Per Click if (populationPerClick == 1) { ppc.text = populationPerClick + " human per click"; } else if (populationPerClick == 0) { ppc.text = populationPerClick + " humans per click"; } else if (populationPerClick > 1) { ppc.text = populationPerClick + " humans per click"; } public void Clicked() { population = population + populationPerClick; } } Progress Bar using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ProgressBar : MonoBehaviour { public Transform LoadingBar; public Transform TextIndicator; public GameObject progressBar; private Population populationScript; private float newPopulation; [SerializeField] private float currentAmount; [SerializeField] private float speed; void Start() { populationScript = GetComponent(); newPopulation = populationScript.population; Debug.Log(newPopulation); } void Update() { if (currentAmount < 100) { currentAmount += speed * Time.deltaTime; TextIndicator.GetComponent().text = ((int)currentAmount).ToString() + "%"; newPopulation = newPopulation + 1; } else { TextIndicator.GetComponent().text = "Done"; currentAmount = 0; } LoadingBar.GetComponent().fillAmount = currentAmount / 100; } } So the error occurs on line 21 in the second script (the progress bar script). Anyone got any ideas? Thanks! ![alt text][1] [1]: /storage/temp/94869-screen-shot-2017-05-27-at-105018-am.png

Weird Error message with empty projects

$
0
0
Hello everyone I'm getting this error message. I have tried everything. It happens with a empty project as well. I tried a fresh install, deleting all files in the project. Reverting the layout. etc But it just sit there. This was first noticed with Surforge, but it is constant now. The error grows when I add surforge to the project which makes me think this more of a unity problem. I appreciate any help. Iam getting this message: NullReferenceException: Object reference not set to an instance of an object UnityEditor.EditorStyles.get_toggleMixed () (at C:/buildslave/unity/build/Editor/Mono/GUI/EditorStyles.cs:131) UnityEditor.EditorGUIInternal..cctor () (at C:/buildslave/unity/build/Editor/Mono/GUI/EditorGUIInternal.cs:20) Rethrow as TypeInitializationException: An exception was thrown by the type initializer for UnityEditor.EditorGUIInternal UnityEditor.EditorWindow.BeginWindows () (at C:/buildslave/unity/build/Editor/Mono/EditorWindow.cs:82) SurforgeInterface.ca8b7d5481922ae00639433ef4dfb015d () SurforgeInterface.Update () System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115) UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:262) UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255) UnityEditor.HostView.SendUpdate () (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:330) UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorApplicationBindings.gen.cs:249) [/QUOTE] Does anyone know what could be causing this and how to fix it?

How to add to a List property in a Class instance...

$
0
0
Hi, having an issue I can't figure out - I have a 'Location' class which has a List property for all the 'Features' in that location - feature being another class type - as you can see below: public class LocationClass { public string lName {get; set;} public string lImageString {get; set;} public bool lVisited {get; set;} private List features; public List lFeatures { get{return features;} set{features = value;} } public LocationClass(string newName, string newImageString) { lName = newName; lImageString = newImageString; lVisited = false; } } In another script, I am attempting to add a 'Feature' to this List, using these commands: foreach (string featureName in lFeatureNames) { FeatureClass lNewFeature = new FeatureClass(featureName); lClass.lFeatures.Add(lNewFeature); } But this is turning up a 'NullReferenceException: Object reference not set to an instance of an object' error. Any ideas? I'm sure it's something to dow with it being a List property, as all the other properties behave as expected... Thanks in advance!

Cant reference Network.Identity connectionInfo

$
0
0
Why does this not work? this.gameObject.name = gameObject.GetComponent ().connectionToClient.connectionId.ToString(); I get an error NullReferenceException: Object reference not set to an instance of an object but somehow I can get it through a collision event just fine void OnCollisionEnter(Collision Other){ Other.gameObject.GetComponent ().connectionToClient.connectionId } What the heck?.

Im Getting an error saying: Object reference not set to an instance of an object although nothing is null.

$
0
0
So.. i am following this tutorial on youtube and i am getting stuck at making the camera. I have tried to add the camera script before the player script in the Script execution order but i still get the same error on line 20. When i press play the script is disabled in the inspector and when i enable it i get another error in line 42 which is added repeatedly. Here is the camera script: public class ThirdPersonCamera : MonoBehaviour { [SerializeField] Vector3 cameraOffset; [SerializeField] float damping; Transform cameraLookTarget; Player localPlayer; void Awake () { GameManager.Instance.OnLocalPlayerJoined += HandleOnLocalPlayerJoined;; cameraLookTarget = localPlayer.transform.Find ("cameraLookTarget"); if (cameraLookTarget == null) cameraLookTarget = localPlayer.transform; } void HandleOnLocalPlayerJoined(Player player) { localPlayer = player; } void Update () { Vector3 targetPosition = cameraLookTarget.position + localPlayer.transform.forward * cameraOffset.z + localPlayer.transform.up * cameraOffset.y + localPlayer.transform.right * cameraOffset.x; transform.position = Vector3.Lerp (transform.position, targetPosition, damping * Time.deltaTime); } } Here is the Player script: [RequireComponent(typeof(CharacterMovement))] public class Player : MonoBehaviour { [System.Serializable] public class MouseInput{ public Vector2 Damping; public Vector2 Sensitivity; } [SerializeField] float speed; [SerializeField] MouseInput MouseControl; private CharacterMovement m_characterMovement; public CharacterMovement characterMovement { get{ if (m_characterMovement == null) { m_characterMovement = GetComponent (); } return m_characterMovement; } } InputController playerInput; void Awake () { playerInput = GameManager.Instance.inputController; GameManager.Instance.LocalPlayer = this; } void Update () { Vector2 direction = new Vector2 (playerInput.Vertical * speed, playerInput.Horizontal * speed); characterMovement.Move (direction); } } I am positive that the errors has to do with the "cameralooktarget" but i would like to know why and how i could fix it. Tell me if you need anymore details, any kind of help is appreciated.
Viewing all 1530 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>