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

UNITY ACCOUNT

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

Navigation

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

Unity account

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

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by caroline13 · Feb 24, 2016 at 02:03 AM · not workinginstanceobject referencesettanks

Object reference not set to an instance of an object (Tanks Tutorial)?

I'm new to Unity and I'm following the Tanks! Tutorial. I've followed the tutorial exactly but keep getting the following error message: "NullReferenceException: Object reference not set to an stance of an object; CameraControl.FindAverage Position () (at Assets/Scripts/Camera/CameraControl.cs:52) It seems to be referring to this block of code:

     private void FindAveragePosition ()
     {
         Vector3 averagePos = new Vector3 ();
         int numTargets = 0;
 
         for (int i = 0; i < m_Targets.Length; i++)
         {
             if (!m_Targets[i].gameObject.activeSelf)
                 continue;
 
             averagePos += m_Targets[i].position;
             numTargets++;
         }

Line 52 is the "if (!m_Targets[i].game.Object.activeSelf) one.

Comment
Add comment · Show 5
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 jgodfrey · Feb 24, 2016 at 02:42 AM 0
Share

Where does the m_Targets array get loaded with data?

avatar image caroline13 jgodfrey · Feb 24, 2016 at 02:53 AM 0
Share

I'm not exactly sure (I only started Unity a few days ago) I think it's this line:

 public Transform[] m_Targets;  








avatar image jgodfrey · Feb 24, 2016 at 03:11 AM 0
Share

No, that line just creates an array of Transforms named m_Targets. Something, somewhere else (either a portion of this script that you didn't post, or another script, or manually within the Unity Inspector) should be inserting one or more Transforms into the m_Targets variable.

avatar image caroline13 jgodfrey · Feb 24, 2016 at 03:24 AM 0
Share

I actually fixed that error now, but it still has the same error message except now it's about a different script (the Tank $$anonymous$$anager one) about line 33, which is this line of code:

 m_$$anonymous$$ovement.m_PlayerNumber = m_PlayerNumber;
avatar image jgodfrey · Feb 24, 2016 at 02:57 PM 0
Share

So, in that case, I'd guess that "m_$$anonymous$$ovement" is null. Look around and try to see where it gets a value assigned to it.

Without more info, it's difficult to say more.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by dos360 · Mar 16, 2016 at 12:38 PM

@jgodfrey @caroline13

I have the same problem as caroline13.

The m_Targets array is loaded with a TankManager array called m_Tanks in the SpawnAllTanks() method in GameManager.cs ; and m_Tanks is initialised in the IDE by assigning a colour and dropping a pair of spawnpoints to an array to two tanks, one blue, the other red.

if two people are making the same mistake, it is likely that there is a problem with the source code supllied. please help.

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

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

50 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

Related Questions

NullReferenceException: Object reference not set to an instance of an object OptionsController.Update () (at Assets/Scripts/OptionsController.cs:26) 1 Answer

“Object reference not set to an instance of an object 1 Answer

Why is object reference not set to an instance? 1 Answer

How to stop my tank from not moving??? 0 Answers

Why do my first 50 instances of a prefab have the same properties? 1 Answer


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