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 janzdott · Aug 24, 2012 at 08:27 PM · arrayfunctiongarbage collector

Reassigning an Array causing problems

Hey guys. I've been working with Unity for a few months now. I've never had to ask a question on here before, because the documentation is great. But I'm just stumped with this one. I would really appreciate the help.

I have an array (myArray). I also have a function (myFunction) that returns an array of Vector3 positions. I want to set myArray equal to the array that myFunction returns. This works perfectly fine... the first time. Then, when I try to change myArray later on, Unity crashes and gives the error message "Fatal Error in Garbage Collector: Too many heap sections". Here is some simple example code...

 var myArray : Array = new Array();
 myArray = myFunction();
 var position : Vector3 = myArray[0];

This works fine. Position is assigned a Vector3, and all is well. Then, when I try to reassign myArray (by doing myArray = myFunction();) some time afterwards, I get the error message. There is nothing wrong with my function. I can call it as much as I want, and assign it to other arrays. But the second I try to reassign an array, I get this error. I also tried this, with no luck....

 myArray = new Array();
 myArray = myFunction();

Could someone please help me? I've been working on this project all night. I've nearly completed it, but this is the only part that has stumped me.

Comment
Add comment · Show 12
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 Tct1856 · Aug 24, 2012 at 09:14 PM 0
Share

I am seeing this error quite often these days "Fatal Error in Garbage Collector: Too many heap sections", is there a possibility that you're using 4.0b7 ?

avatar image janzdott · Aug 24, 2012 at 09:19 PM 0
Share

Yeah I was planning on switching to lists or binary heaps. It's for a nav$$anonymous$$esh pathfinding system I'm making. I just wanted to get it working first before I make it more complicated. All of the pathfinding works. The character navigates his way to the waypoint. But as soon as I store a new path in the array, it crashes. And no, I'm using 3.5.2f2

avatar image janzdott · Aug 24, 2012 at 09:50 PM 0
Share

I'm sure lists are better to use... but I don't think that's the problem. I just did a test where I calculated 10 paths to 10 random locations every frame in an update function. Still got well over 200 frames per second. And no garbage collector error. I dont think the problem is co$$anonymous$$g from my pathfinding function. It only happens when I reassign an array... I don't understand why

avatar image fafase · Aug 24, 2012 at 09:50 PM 1
Share

What is the function? And even if you really would not want to use List as suggested you should at least use the built-in arrays.

avatar image fafase · Aug 24, 2012 at 11:00 PM 1
Share

Arrays do not change size. Use list. If you are trying to extend your array you are getting out of bounds and that is dangerous to the application. Use list, it is like array but flexible, Edit: yes Js Array are sizeable.

Show more comments

2 Replies

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

Answer by janzdott · Aug 26, 2012 at 06:41 PM

It took hours of debugging, and I found that there was a problem with my pathfinding function. There was an infinite loop, but it only occured when calculating a new path. I fixed it and my pathfinding is fully functional now. This is being designed for an Android game, so its very simplistic and easy to use. I will hopefully post my work soon, after some optimization of course :)

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
0

Answer by RuslanDavletshin · Aug 26, 2012 at 08:44 PM

http://answers.unity3d.com/questions/308523/sprint-stamina-guys.html

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

12 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

Related Questions

Spaceship game, Pick weapon 1 Answer

Storing functions in a list/array? 1 Answer

Array problem? help please! 1 Answer

Add a temporary variable to an array 1 Answer

Array Problem - Error Code BCE0022 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