Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by phiniusmaster · Apr 12, 2012 at 05:51 PM · instantiatetransformchild

UnityException: Transform child out of bounds.

I'm getting the error in the title from this line:

 droneArray[c] = Instantiate(droneConstruct,spawnpointStack.GetChild(spc).position,Quaternion.LookRotation(transform.position));

EDIT So I fixed the problem, but now I'm getting this:

"NullReferenceException: Object reference not set to an instance of an object"

Why, Unity! Why!

Comment
Add comment
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 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CHPedersen · Apr 12, 2012 at 05:59 PM

As a general rule of thumb, a NullReferenceException always means you are attempting to access a member of an object, be it class field or method, the reference to which is null. This typically occurs because an attempt to acquire a reference failed, such as through the use of GetComponent where a scriptname is spelled wrong, the gameobject doesn't have that component attached at all, or perhaps a call to GameObject.Find where the wanted gameobject's name is invalid.

It's hard to know just what's wrong in your case because you only posted one line of code, naturally. But if I were to venture a quick guess, anyway, I'd bet it's probably spawnpointStack being null. Check the state of that object before the line you posted by simply shooting the variable into a call to Debug.Log. Does that print "null" to the console?

If not, it is likely the prefab you're trying to instantiate a copy of, that is, the object called "droneConstruct". Is this a public variable in your script which is supposed to reference a prefab in your project? If so, have you remembered to drag the prefab onto that variable in the editor?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiating a new gameObject as a child of a different gameObject 2 Answers

2D platformer firing left and right, help! 1 Answer

Delete children of Instantiated object 2 Answers

Instantiate a Prefab as child 0 Answers

Creating new Transform from existing objects Transform to Instantiate object 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