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 camtronius · May 21, 2014 at 05:27 AM · transform.positionpathfindingpathrtsfixedupdate

How to call a method once inside fixed update

Hey guys, I am trying to set a units pathing position to another unit if they are within a certain distance to each other. The problem is that my distance detection is in fixedUpdate method, and if I want to change the path he is on I have to do it here too. When I do this, it repeatedly adds the new waypoint for the unit to travel, and eats up my memory like crazy. I am wanting to know if there is a way to call my pathing waypoint just once, or maybe even like once every few seconds. Thanks guys,

public void Start () {

     CreateBehavior (); //determines whether the unit goes to a tower or the base
     FindCloseUnits (); //finds all the player controlled units on the map and adds them to a list

     seeker = GetComponent<Seeker>();
     controller = GetComponent<CharacterController>();

     //behavior code conditions
     GameObject towerObject = GameObject.Find("Cylinder");
     Tower towerCaptureObject = towerObject.GetComponent<Tower>();


     seeker.StartPath (transform.position, targetPosition, OnPathComplete); //makes the path the unit follows

     
 }



public void LocalAvoidance(){ //do the distance of specific vectors like x,z to determine direction unit is pushed back

     for (int i=0; i<UnitsList.Count; i++) { //this iterates through my list of unit objects
             
             float distance = Vector3.Distance (transform.position, UnitsList[i].transform.position);
             //this calculates the distance from one unit to another
             
             if (distance <= 5) { //if the distance is less than 1.5 push the unit away
                 
             targetPosition = UnitsList[i].transform.position;
                              seeker.StartPath (transform.position, targetPosition, OnPathComplete); //makes the path the unit follows

//this is where it buggs out and eats all my memory. I need the seeker.startpath function to be called only once with the new target position unless the other unit changes positon, then it will get his position... } }

 }



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 JasonBricco · May 21, 2014 at 05:35 AM 1
Share

Not sure I understand, but if your problem is that something is being called repeatedly in FixedUpdate and you want to make it call just once, you could use a boolean switch. Say in FixedUpdate to only call it when the boolean is true, then once you call it set it to false.

As for every few seconds, you could make a coroutine that sets it to true every few seconds.

I'm not sure if I'm understanding properly, though.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Noob_Vulcan · May 21, 2014 at 05:52 AM

If you want to call that method once then use bool i.e.

 bool isTemp=false;
 
 if(!isTemp){
 //call you fucntion
 isTemp=true;
 }

i think this wat u want. If want to call it in every 1 sec then you can use WaitForSeconds

http://docs.unity3d.com/Documentation/ScriptReference/WaitForSeconds.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

22 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

Related Questions

How to detect multiple objects for avoidance 1 Answer

Collision Avoidance causes jiggling 2 Answers

unitySteer + path for racing AI 2 Answers

making a path 1 Answer

Path system or Predetermined paths for Camera Fly-throughs / Ladder climbing / etc 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