Get 25% off your next order from the Unity Asset Store: YW86GYBU8S.
Forum begins after the advertisement:
[Part14]NullReferenceException: Object reference not set to an instance of an ob
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [Part14]NullReferenceException: Object reference not set to an instance of an ob
- This topic has 11 replies, 3 voices, and was last updated 1 year, 10 months ago by
Terence.
-
AuthorPosts
-
December 10, 2023 at 9:40 pm #12564::
I have followed the instructions from the tutorial but it seems there is an error like this.
The damage text never shown in my code.
NullReferenceException: Object reference not set to an instance of an object GameManager+<GenerateFloatingTextCoroutine>d__31.MoveNext () (at Assets/Scripts/GameManager.cs:131) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <cd14705e8f094afcb566740ab5e8c02d>:0) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) GameManager:GenerateFloatingText(String, Transform, Single, Single) (at Assets/Scripts/GameManager.cs:164) EnemyStats:TakeDamage(Single, Vector2, Single, Single) (at Assets/Scripts/Enemy/EnemyStats.cs:60) ProjectileWeaponBehaviour:OnTriggerEnter2D(Collider2D) (at Assets/Scripts/Weapons/Weapon Base/ProjectileWeaponBehaviour.cs:99)December 10, 2023 at 11:02 pm #12565::Hi Burhan, make sure that you have assigned all the new properties on the GameManager.
Failing that, check out this video to troubleshoot your NullReferenceException.
December 11, 2023 at 4:38 am #12567December 11, 2023 at 3:44 pm #12569December 11, 2023 at 5:16 pm #12571::Burhan, can you double click on the NullReferenceException in your Console? This should bring you to the line of code that is the issue on Visual Studio. Screenshot that and show me what line it is.
December 11, 2023 at 5:17 pm #12572::You can also check out this topic and see if it helps: https://blog.terresquall.com/community/topic/part-14-missingreferenceexception-with-floating-text-recttransform/
December 12, 2023 at 12:00 am #12576December 12, 2023 at 3:22 pm #12588::Burhan,
Add the following lines above line 131, run the game, and show me the result on the Console.
Debug.Log("textObj: " + textObj); Debug.Log("instance: " + instance); Debug.Log("damageTextCanvas: " + damageTextCanvas);One of your variables on Line 131 is null, and that is what is causing the null reference.
December 13, 2023 at 12:15 am #12622December 13, 2023 at 11:14 am #12631::Burhan, I found the issue. You have an extra portion in your code:
textObj.transform.parent.SetParent(instance.damageTextCanvas.transform);textObjhas no parent, so when you try to access its parent, you are essentially doingnull.SetParent(), which is what causes the code to fail.December 17, 2023 at 6:52 pm #12692December 21, 2023 at 9:45 pm #12724 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below:
Get 25% off your next order from the Unity Asset Store: YW86GYBU8S.
