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 /
avatar image
0
Question by martingee · Aug 27, 2011 at 10:55 AM · arrayvariablerenderer

When using an Array i get a NullReferenceException

So i'm currently looking to implement a spawning script for my character which amongst other things will turn off his visibilty upon entering a 'death' trigger box and make him reappear when he respawns.

The problem i'm having is that my character is in several parts and so to access the Renderer in all parts i used a bulletin array and populated with my character's mesh's.

This is the script:

 var spawnpointdeath : Transform;
 var character : Renderer[];


 function OnTriggerEnter(other : Collider) {
  if (other.tag == "Player") {
     character.renderer.enabled = false;
     
     yield WaitForSeconds (.5);
     
     other.transform.position = spawnpointdeath.position;
     
     character.renderer.enabled = true;


  }
 }

When i run the game i get the error 'NullReferenceException: Object reference not set to an instance of an object'.

If i don't use an array and just add one element of my characters mesh to a variable it works fine and obviously with the error message all things point to my array but i'm not sure whats going on. Do i need to make instances of my characters meshes to make it work? I don't understand why it would work as a variable with one mesh and not an array with several meshes.

As you might have guessed, I'm new to Unity and to scripting and have for the last couple of days been searching and trying to work out what i'm doing wrong but can't seem to find the answer. Any help would be greatly appreciated :)

Comment
Add comment · Show 2
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 Dreamish · Aug 27, 2011 at 11:43 AM 0
Share

The error message itself though comes from not assigning objects to the array. Do this for every position of the array in the inspector.

If you've done this, and it still doesn't work, try this:

Since character is an array I think you have to specify position, for example: character[0].renderer.enabled = false;

So if you want to set the whole array to false you need to iterate through each position: for (var i = 0; i < character.length; i++) { character[i].renderer.enabled = false; }

avatar image martingee · Aug 27, 2011 at 01:27 PM 0
Share

Didn't realise i had to make it apply to each entry (one by one or through iteration), i thought by default it would just apply it to the whole array.

This worked a treat, thanks Dreamish! Though i can't make your response an answer, i think you'd have to repost.

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by cvgwegwegwe · Aug 27, 2011 at 12:34 PM

ONLINE STORE :

====( http://popbuynow.com/ )=====

The website wholesale for many kinds of fashion shoes, like the nike,jordan,prada,, also including the jeans,shirts,bags,hat and the decorations. All the products are free shipping, and the the price is competitive, and also can accept the paypal payment.,after the payment, can ship within short time.

free shipping

competitive price

any size available

accept the paypal

jordan shoes $32

nike shox $32

Christan Audigier bikini $23

Ed Hardy Bikini $23

Smful short_t-shirt_woman $15

ed hardy short_tank_woman $16

Sandal $32

christian louboutin $80

Sunglass $15

COACH_Necklace $27

handbag $33

AF tank woman $17

puma slipper woman $30

====( http://popbuynow.com/ )=====

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
-1

Answer by cvgwegwegwe · Aug 27, 2011 at 12:37 PM

ONLINE STORE :

====( http://popbuynow.com/ )=====

The website wholesale for many kinds of fashion shoes, like the nike,jordan,prada,, also including the jeans,shirts,bags,hat and the decorations. All the products are free shipping, and the the price is competitive, and also can accept the paypal payment.,after the payment, can ship within short time.

free shipping

competitive price

any size available

accept the paypal

jordan shoes $32

nike shox $32

Christan Audigier bikini $23

Ed Hardy Bikini $23

Smful short_t-shirt_woman $15

ed hardy short_tank_woman $16

Sandal $32

christian louboutin $80

Sunglass $15

COACH_Necklace $27

handbag $33

AF tank woman $17

puma slipper woman $30

====( http://popbuynow.com/ )=====

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Make an array of scripts? 1 Answer

How to get a value from an array within another script. 1 Answer

Different way to access class variables? 1 Answer

How to get the number of variables in a class, and then call the variable by its number. 1 Answer

Getting A Variable From a Outside Text File 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