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 1337GameDev · Jan 14, 2015 at 07:58 AM · c#errorarraylengthincorrect

c# array size doesn't grow past 10 (bracket initialization)

I have a singleton script, that all it does is handle / process arrays of names of layers, and then calls Physics.IgnoreLayerCollision on specific ones from specific lists.

The problem is, inside my script i have this array:

 private string[] noSelfCollisions = {
         "Team1",
         "Team2",
         "Team3",
         "Team4",
         "Team5",
         "Team6",
         "Team7",
         "Team8",
         "NPC",
         "RTSUnit",
         "Obstacles",
         "Grid",
         "Ground",
         "Selectable",
         "Default"
     };


And then the inspector (even before I hit play) only shows the array until "Obstacles" and it's length as 10.

This is obviously wrong, and confuses me. The script has been recompiled, I have tried adding values and making the variable public, then private again (to force a recompile) but to no avail.

What could be causing this to happen? I'm confused to no end about this.

Comment
Add comment · Show 3
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 CHPedersen · Jan 14, 2015 at 08:09 AM 1
Share

Are you sure noSelfCollisions is actually the array you're looking at in the inspector? I suspect it's something else, because private arrays are not serialized by default, so unless you have the [SerializeField] attribute directly above this declaration, it will not show in the editor.

avatar image zharik86 · Jan 14, 2015 at 08:12 AM 2
Share

Unity saves your actions, including values of variables. Just rename your array. Save it. And rename at original name once again and save.

avatar image 1337GameDev · Jan 14, 2015 at 05:25 PM 0
Share

If enabled "debug inspector" you can view private fields without having to serialize them.

zharik86 was correct and his answer solved my problem. The compiler in unity, for some wierd reason, was skipping this part of code as needing to be recompiled and used and old compiled version for this section.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by 1337GameDev · Jan 14, 2015 at 05:22 PM

Unity saves your actions, including values of variables. Just rename your array. Save it. And rename at original name once again and save.

The user: agozharik86

This answer was correct. I thought changing values of the array would cause unity to retouch the array and compile it with new data, but you have to rename it. Something in it's compiler was stuck and would not recompile this part of code.

So in all, the problem is fixed, and for future reference to anybody, rename variables when they "stop" changing to have unity recompile them.

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 Berenger · Jan 14, 2015 at 08:16 AM

Something is messing with your array. Either you're not printing the correct one, or noSelfCollisions's value changes. Might be one of your scripts, or Unity (but the array was private to begin with, so it's probably not the issue). Initialize your array in Start or Awake, and print it right away, the values should be correct.

Try to find every affectation to this array in your code.

Comment
Add comment · Show 1 · 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 1337GameDev · Jan 14, 2015 at 05:23 PM 0
Share

I thought it was being changed too, but that was not the case. The code was verbatim what i posted on a new script I created.

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

27 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

Related Questions

Problem with List not filling using add method in a foreach loop 1 Answer

Why ExecuteInEditMode Always Causes NullReferenceException Errors Even In Clamping!! 2 Answers

Object reference not set to an instance of an object error C# 1 Answer

Npc Quest System Array Error 0 Answers

error CS0236: A field initializer cannot reference the nonstatic field, method, or property 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