Support Forum

_richAI.SetPath called in the callback of _seeker.StartPath error

Hello,
I am having a problem with starting a path (I am trying to do flee behaviour) on my RichAI script.
It is most probable that I do not understand how to work with both RichAI and the underlying seeker :slight_smile:

My reasoning goes like this:

  1. I create the flee path
  2. I start the path calculation on the seeker
  3. In the callback (once it is calculated), I set the path to the RichAI
  4. the character will flee, yeeey

Code:

 public void Flee(OfficeWorkerAI from) {
           
            Running = true;
            _movementScript.maxSpeed = 3f;
            _movementScript.canSearch = false;
            
            Vector3 thePointToFleeFrom = from.transform.position;
            int theGScoreToStopAt = 100000;
        
            FleePath path = FleePath.Construct (transform.position, thePointToFleeFrom, theGScoreToStopAt);
         
            path.spread = 1000;
            Transform exit = GameObject.Find("Exit").transform;
            
            Debug.Assert(exit != null, "exit != null");
            path.aim = exit.position;
            path.aimStrength = 10000;
            
            Seeker seeker = GetComponent<Seeker>();

            seeker.StartPath(path, p => {
                TrySetCanMove(true);
                _movementScript.SetPath(p);
              
            });
        }

However, I keep getting this error, even though I am using the callback so the path should be done.

ArgumentException: You must call the SetPath method with a path that either has been completely calculated or one whose path calculation has not been started at all. It looks like the path calculation for the path you tried to use has been started, but is not yet finished.

Hi

This particular use case has been fixed in the beta version (calling SetPath from the path complete callback).

However, I would recommend that you just let the RichAI handle the communication with the seeker.

FleePath path = FleePath.Construct (transform.position, thePointToFleeFrom, theGScoreToStopAt);
path.spread = 1000;
Transform exit = GameObject.Find("Exit").transform;
            
Debug.Assert(exit != null, "exit != null");
path.aim = exit.position;
path.aimStrength = 10000;

// This will make the RichAI script communicate to the Seeker that it should start calculating the path
// _movementScript.pathPending will be true while the path is being calculated
_movementScript.SetPath(path);

Essentially you can just do

  1. I create the flee path
  2. I send the path to the RichAI
  3. the character will flee, yeeey

Thanks, I did not know I can do it so simple! It works :slight_smile:

The only issue is what if I would need to do something in the callback when the path is done calculating? For example starting the animation only then, so that it starts running when he has the path ready and there is no visible lag?

With SetPath there is no callback option …

Oh my mistake, I did not notice the comment and the path.pending … I guess that solves my question :relaxed: @aron_granberg

1 Like