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 Stone-Legion · Dec 20, 2013 at 02:34 PM · c#arraybugvector

Vector4 values disappearing from Array, Unity C# bug?

I've been struggling with what almost seems like a potential bug with C# and Unity. I've built an array of Vector4's that is 16 items in length. I assign the values to each position in the array from 0 to 15. Later on, I call the index position of the item I need within the array bounds, only to find that the Vector4 values have been reset to zero. This is done all from within the game gameobject, same script, it has not been reset/modified/disabled in any way.

This doesn't make sense to me because the only place in the script where the Vector4 values are set is within void Start(). They are not modified anywhere else. After Start() I've gone through a for loop to print each item from the array to ensure they are actually set, which they are because you can see the values printed to console. Nonetheless, when I call them after this, it's as if they were never set and it's driving me crazy. I've gone through my code for over an hour ensuring the array isnt being modified anywhere else.

Has anyone else had similar behaviour with Unity and C#? This seems like some sort of memory bug.

 Vector4[] poolPositionArray = new Vector4[16]; 
 
 void Start()
 {
     for(int i = 0; i < poolPositionArray.Length; i++)
     {

        [...]
        poolPositionArray[i] = new Vector4(topLeftX, topLeftY, bottomRightX, bottomRightY);
        Debug.Log ("Pool index #"+i+" is positioned at "+poolPositionArray[i]);
     }
 }

 void OnClick()
 {
     for (int i = 0; i < poolPositionArray.Length; i++)
     {        
          Debug.Log ("Pool index #"+i+" is positioned at "+poolPositionArray[i]);
     }
 }
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
-1

Answer by merkaba48 · Dec 20, 2013 at 04:54 PM

I think from a probability point of view, it's unlikely to be a bug in Unity. I think it's easiest for you to debug this yourself. Try to determine the exact moment in script when the array goes from containing members to containing nothing; use the Monodevelop debugger to do this. But before you do that, be sure to check that your array is populated correctly before that code block ends, by printing its objects directly; e.g.

Debug.Log( poolPosition.ToString() )

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

19 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

Related Questions

How to check if vector in array was not changed? 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Using a footstep C# script and keep getting an "IndexOutOfRangeException" 2 Answers

just update X and Z position of gameobject 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