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 /
This question was closed Jan 17, 2015 at 11:45 PM by KazeEnji for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by KazeEnji · Jan 09, 2013 at 09:26 PM · javascriptpathfindingarraylist

Unity is recording all info gathered from separate pathfinders into a single array. Why? (JS)

Here's my code:

 function OnTriggerEnter(other:Collider)
 {
     if(other.tag=="pathfinder")
     {
         Debug.Log("I hit the pathfinder");
         
         //Variables for potential rapid single use
         var clone:Rigidbody;
         var moveDistance:int;
         
         //Copies pathfinder's history data to an internal variable for the waypoint
         tempMyPathList=other.GetComponent("Pathfinder").myPathList;
         tempMyPathList.Add(this.gameObject);        
         moveDistance=other.GetComponent("Pathfinder").distance;
         
         //Checks if it's the last waypoint within moving distance
         if(moveDistance>0)
         {
             //If it's not the last, it subtracts 1 from current value to give to next Pathfinder
             moveDistance=moveDistance-1;
             
             /*
             Checks to see which waypoint surrounding this one
             sent the Pathfinder in order to avoid sending a
             pathfinder backwards. Whichever direction is
             determined as the sending waypoint, this waypoint
             will not send a pathfinder towards it.
             */
             if(forwardWaypoint.tag=="waypoint" && other.GetComponent("Pathfinder").originWaypoint!=forwardWaypoint)
             {
                 //Creates a new Pathfinder, changes it's name, assigns it variables, and sends it out in the forward direction
                 clone=Instantiate(pathfinder, forwardSpawner.transform.position, forwardSpawner.transform.rotation);
                 clone.name=this.gameObject.name+"PathfinderForward";
                 clone.GetComponent("Pathfinder").myPathList=tempMyPathList;
                 clone.GetComponent("Pathfinder").originWaypoint=this.gameObject;
                 clone.GetComponent("Pathfinder").distance=moveDistance;
                 clone.velocity=transform.TransformDirection(Vector3.forward*75);
             }
             
             if(rightWaypoint.tag=="waypoint" && other.GetComponent("Pathfinder").originWaypoint!=rightWaypoint)
             {
                 //Creates a new Pathfinder, changes it's name, assigns it variables, and sends it out in the right direction
                 clone=Instantiate(pathfinder, rightSpawner.transform.position, rightSpawner.transform.rotation);
                 clone.name=this.gameObject.name+"PathfinderRight";
                 clone.GetComponent("Pathfinder").myPathList=tempMyPathList;
                 clone.GetComponent("Pathfinder").originWaypoint=this.gameObject;
                 clone.GetComponent("Pathfinder").distance=moveDistance;
                 clone.velocity=transform.TransformDirection(Vector3.right*75);
             }
             
             if(leftWaypoint.tag=="waypoint" && other.GetComponent("Pathfinder").originWaypoint!=leftWaypoint)
             {
                 //Creates a new Pathfinder, changes it's name, assigns it variables, and sends it out in the left direction
                 clone=Instantiate(pathfinder, leftSpawner.transform.position, leftSpawner.transform.rotation);
                 clone.name=this.gameObject.name+"PathfinderLeft";
                 clone.GetComponent("Pathfinder").myPathList=tempMyPathList;
                 clone.GetComponent("Pathfinder").originWaypoint=this.gameObject;
                 clone.GetComponent("Pathfinder").distance=moveDistance;
                 clone.velocity=transform.TransformDirection(Vector3.left*75);
             }
             
             if(backWaypoint.tag=="waypoint" && other.GetComponent("Pathfinder").originWaypoint!=backWaypoint)
             {            
                 //Creates a new Pathfinder, changes it's name, assigns it variables, and sends it out in the back direction
                 clone=Instantiate(pathfinder, backSpawner.transform.position, backSpawner.transform.rotation);
                 clone.name=this.gameObject.name+"PathfinderBack";
                 clone.GetComponent("Pathfinder").myPathList=tempMyPathList;
                 clone.GetComponent("Pathfinder").originWaypoint=this.gameObject;
                 clone.GetComponent("Pathfinder").distance=moveDistance;
                 clone.velocity=transform.TransformDirection(-Vector3.forward*75);
             }
         }
         else
         {
             /*
             If this is the last waypoint withing moving
             distance, this waypiont will render a particle
             system to signify that it is a valid move.
             */
             moveParticles.renderer.enabled=true;
             
             for(var value in tempMyPathList)
             {
                 Debug.Log(value);
             }
             
                 Debug.Log(tempMyPathList.Count);
         }
         Destroy(other.gameObject);
     }
 }

So all the variables are working properly, they're recording and everything. The code you see is sitting on my waypoint, the pathfinder object it's looking for has just a few variables in it and that's it.

My problem is that at the end, I have a function that logs the value in the myPathList variable and somehow it's recorded all of the waypoints that all of the pathfinders hit. It should be that each waypoint is holding a single list of waypoints that the pathfinders have followed.

I feel like it has something to do with the instantiate code somehow creating another instance of the same object so every time a pathfinder hits something, it gets recorded on a single list.

I hope this is all making sense, I'd be happy to elaborate if I'm not clear on something. Just been banging my head against a wall for the past week trying different things and I'm stuck.

Thanks ahead of time for the help! -Kaze-

Comment
Add comment · Show 1
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 KazeEnji · Jan 10, 2013 at 02:48 PM 0
Share

I'm going to rephrase this question, this thread is dead now.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A* nodes in the basic version of unity. 1 Answer

AI Pathfinding Script 4 Answers

Need to change direction of transform? 2 Answers

Implicit downcast and ArrayList 1 Answer

Path finding using Raycasting inside of Unity(JavaScript) 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