Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Naexys24 · Apr 21, 2019 at 10:42 AM · nullbug reportindex

"Object at index 0 is null"

Hi, I'm making a tower defense, and when i want to draw the line to the enemy, I ve this eror : "Object at index 0 is null". The fact is, my program is working, but I've this error when i launch it. Thanks for the answer

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Turret : MonoBehaviour {
 
     [Header("Finding the closest enemy")]
     public Transform target;
 
     [Header("Values")]
     public float range = 15f;
     public string enemyTag = "Enemy";
 
     [Header("LineRenderer")]
     private LineRenderer line;
     public Transform origin;
     public float lineDrawSpeed = 1f;
     private float counter;
     private float dist;
 
     void Start () {
         line = GetComponent<LineRenderer>();
         line.SetPosition(0, origin.position);
         line.SetWidth(0.45f, 0.45f);
 
         InvokeRepeating("UpdateTarget", 0f, 0.2f);
     }
 
     void UpdateTarget()
     {
         GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyTag);
         float shortestDistance = Mathf.Infinity;
         GameObject nearestEnemy = null;
 
         foreach(GameObject enemy in enemies)
         {
             float distanceToEnemy = Vector3.Distance(transform.position, enemy.transform.position);
             if(distanceToEnemy < shortestDistance)
             {
                 shortestDistance = distanceToEnemy;
                 nearestEnemy = enemy;
             }
         }
 
         if(nearestEnemy !=null && shortestDistance <= range)
         {
             target = nearestEnemy.transform;
         }
         else
         {
             target = null;
         }
 
 
     }
     
     void Update () {
         if (target == null)
         {
             
             counter = dist = 0;
             line.enabled = false;
         }
         else
         {
             line.enabled = true;
             dist = Vector3.Distance(origin.position, target.position);
             Vector3 pointA = origin.position;
             Vector3 pointB = target.position;
             if (counter < dist)
             {
                 counter += 0.1f / lineDrawSpeed;
             }
             float l = Mathf.Lerp(0, dist, counter);
             Vector3 pointAlongLine = l * Vector3.Normalize(pointB - pointA) + pointA;
             line.SetPosition(1, pointAlongLine);
 
         }
 
     }
     void OnDrawGizmosSelected()
     {
         Gizmos.color = Color.red;
         Gizmos.DrawWireSphere(transform.position, range);
     }
 }


 ArgumentException: Object at index 0 is null
 UnityEditor.SerializedObject..ctor (UnityEngine.Object[] objs, UnityEngine.Object context) (at C:/buildslave/unity/build/Editor/Mono/SerializedObject.bindings.cs:39)
 UnityEditor.Editor.GetSerializedObjectInternal () (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:553)
 UnityEditor.Editor.get_serializedObject () (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:452)
 UnityEditor.UIElements.InspectorElement..ctor (UnityEditor.Editor editor, Mode mode) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorElement.cs:133)
 UnityEditor.UIElements.EditorElement.Init () (at C:/buildslave/unity/build/Editor/Mono/Inspector/EditorElement.cs:84)
 UnityEditor.UIElements.EditorElement..ctor (Int32 editorIndex, UnityEditor.InspectorWindow iw) (at C:/buildslave/unity/build/Editor/Mono/Inspector/EditorElement.cs:62)
 UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1392)
 UnityEditor.InspectorWindow.RebuildContentsContainers () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:639)
 UnityEditor.InspectorWindow.RedrawFromNative () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:311)
 


Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Midaroh · Apr 22, 2019 at 10:32 PM 0
Share

I'm getting nearly the same error. I pasted my error message here and bolded the differences. I started seeing this issue when upgrading to the new 2019 build. It seems when making changes to the game using the editor causes this error to appear when trying to run the game. Restarting Unity fixes it until I make another change. I haven't found a solution yet.

ArgumentException: Object at index 0 is null UnityEditor.SerializedObject..ctor (UnityEngine.Object[] objs, UnityEngine.Object context) (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/SerializedObject.bindings.cs:39) UnityEditor.Editor.GetSerializedObjectInternal () (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/Inspector/Editor.cs:553) UnityEditor.Editor.get_serializedObject () (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/Inspector/Editor.cs:452) UnityEditor.UIElements.InspectorElement..ctor (UnityEditor.Editor editor, UnityEditor.UIElements.InspectorElement+$$anonymous$$ode mode) (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/Inspector/InspectorElement.cs:133) UnityEditor.UIElements.EditorElement.Init () (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/Inspector/EditorElement.cs:84) UnityEditor.UIElements.EditorElement..ctor (System.Int32 editorIndex, UnityEditor.InspectorWindow iw) (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/Inspector/EditorElement.cs:62) UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/Inspector/InspectorWindow.cs:1392) UnityEditor.InspectorWindow.RebuildContentsContainers () (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/Inspector/InspectorWindow.cs:639) UnityEditor.InspectorWindow.RedrawFromNative () (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/Inspector/InspectorWindow.cs:311)

9 Replies

· Add your reply
  • Sort: 
avatar image
12

Answer by gaggedegg · May 30, 2019 at 09:33 AM

You can remove this error by closing and again adding the Inspector window.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MemeDream · Jun 01, 2019 at 07:39 PM 0
Share

Thanks, this worked for me.

avatar image Midaroh · Jun 04, 2019 at 07:06 AM 0
Share

This solved the issue for me as well.

avatar image VoidVenom · Jul 07, 2019 at 06:13 AM 0
Share

Worked for me. Seems there is a bug with opening a second inspector, then closing the first causes index 0 to be null but index 1 (the second inspector open) not. Unity can fix this easily... I feel let down.

avatar image David-Filipe · Jan 17, 2020 at 09:37 AM 0
Share

Can confirm tha tthis is the case

avatar image
7

Answer by elijahjns · May 18, 2019 at 06:43 PM

I got this error because I had two inspectors open on two different items both with scripts. I hope this helps.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image elijahjns · May 18, 2019 at 06:51 PM 0
Share

Actually it's happening if I start the game with any scripted object selected. What an odd error.

avatar image Midaroh elijahjns · May 20, 2019 at 01:21 AM 0
Share

Looks like you are right. I have been having the same issue, and here I was restarting Unity to make it go away. But CTRL+clicking to deselect the object before running the game does keep the error from appearing.

I'm still wondering if there is something within our projects that is causing this or is it totally Unity's fault. It seems that not a whole lot of people are complaining about it.

avatar image BeyondMASC · May 29, 2019 at 11:07 AM 0
Share

Wow never thought. Thanks!

avatar image Motawea · Jul 03, 2019 at 09:38 AM 0
Share

That was the case with me too, Thanks!

avatar image
2

Answer by tylerwongj · Oct 12, 2019 at 12:24 AM

Seems like this error is in regards to the Unity Editor - after trying to open/close the Inspector window (which worked once, but didn't work again), I literally just:

Restarted Unity and it worked!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by sp3cim4n_ · Apr 21, 2019 at 12:07 PM

these kind of errors are mostly related to order of execution.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by MrSmokes · May 23, 2019 at 03:05 PM

Can confirm it's an inspector error - unity 2019.1.3f1

kept getting this error at runtime when using an object pool - but only if one of my game objects containing an object pool was selected in the inspector. (i have a script for spawnwaves on the same gameobject so it's selected a lot)

if i chose another object in the inspector the error would disappear - which i only realised when i checked this thread - as it hadn't been having any impedance on my project, it was just kinda annoying.

hope this helps.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

118 People are following this question.

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

Related Questions

Array error - Index is less than 0... 3 Answers

Null first array index and shift rest by 1? 1 Answer

TileBase array conversion to list not clearing? 1 Answer

transform is destroyed (ERROR)... and I want the game to complete 1 Answer

Matching Index of two Arrays after one Array is sort 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges