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 /
  • Help Room /
This question was closed Mar 05, 2016 at 03:24 PM by Griffo for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Griffo · Mar 04, 2016 at 01:28 PM · listnavmeshnavmeshagentlists

Why is my list bigger than it should be?

I'm generating 3 random waypoints then saving them to a list but when debugged the list is showing a Count of 5, why?

 function getWaypionts ()
 {
     for (var l=0; l < 3; l++)
     {
         Debug.Log("l is " + l);
         var walkRadius : float = 10;
         var randomDirection : Vector3 = Random.insideUnitSphere * walkRadius;
         randomDirection += transform.position;
         var hit : NavMeshHit;
         NavMesh.SamplePosition(randomDirection, hit, walkRadius, 1);
         var finalPosition : Vector3 = hit.position;

         waypoints.Add(finalPosition);
     }
     for (var lk=0; lk < waypoints.Count; lk++)
     {
         Debug.Log("waypoint " + lk + " is " + waypoints[lk]);
     }
     waypointsGenerated = true;
 }

alt text

screen-shot-2016-03-04-at-131545.png (48.5 kB)
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

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Exceptione · Mar 04, 2016 at 01:33 PM

Do you have any in the inspector of the script in Unity that are already in the list before you run the game?

If not, make sure you're not adding them from anywhere else. At first glance I can't see anything wrong with the code.

Comment
Add comment · Show 2 · 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 Griffo · Mar 04, 2016 at 01:39 PM 1
Share

O$$anonymous$$G, I'd left the var public and must have set it to 2 sometime, thats where they came from, cheers, convert your comment to an answer and I'll accept it.

avatar image Exceptione Griffo · Mar 04, 2016 at 03:11 PM 0
Share

Done! We all make small mistakes ;)

avatar image
3

Answer by phil_me_up · Mar 04, 2016 at 01:38 PM

As Exceptione said, make sure you don't have anything added to the list within the inspector.

I'd suggest making it a private variable, or perhaps tagging with [HideInInspector] if you don't actually want to be able to edit these values at edit time.

It might be sensible to run .Clear() on the list before you start adding your data too.

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

Follow this Question

Answers Answers and Comments

37 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

nav mesh agent problem, can only be called on active agent that has been placed on a nav mesh 1 Answer

Spawning large numbers of navmeshagents causes them to jump position 0 Answers

Navmesh Agent trigger ? 1 Answer

Is there a way to modify my script a path, before setting it to a NavmeshAgent 0 Answers

=> How to Avoid NavMeshAgents Clumping Up Together?! <= 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