MotionEvent stop when switching MotionPath on the last waypoint

Hello,

I’m currently using the MotionEvent control to set the movement of my spatial, it currently work as when the user set a destination point, the MotionEvent using a MotionPath make the spatial move from A → B, no issue there. During the MotionEvent.play, each time the MotionEvent reach a wayPoint i check if the user have set a new destination point, if so, a new MotionPath is build and replace the one currently used to fit the new destination point.

The issue i’m facing there is when switching the MotionPath while the reaching the last wayPoint, i don’t know why the MotionEvent don’t want to move anymore, the path is currectly set/update (i use the debugPath) but the spatial just don’t move, i’m facing this issue only when switching the motionPath when reaching the lastWaypoint, all other wayPoint work just fine. i’m for sure missing something.

Used Code :

    //Part used to initialise the control.
    MotionPath motionPath = addPathListener(e.getId(), buildPath(null, path));
    MotionEvent motionControl = new MotionEvent(renderSystem.getSpatial(e.getId()),
                        motionPath, ms * path.size());
    motionControl.setDirectionType(MotionEvent.Direction.Path);
    motionControl.play();

    //Part used to initialise and set the listeners.
    private MotionPath addPathListener(final EntityId id, MotionPath path) {
        path.addListener(new MotionPathListener() {
            @Override
            public void onWayPointReach(MotionEvent control, int wayPointIndex) {
                if (control.getPath().getNbWayPoints() == wayPointIndex + 1) {
                    System.err.println(control.getSpatial().getName() + " has finished moving. ");
                } else {
                    System.err.println(control.getSpatial().getName() + " has reached way point " + wayPointIndex);
                }
                updatePosition(id, control);
                if (movementUpdateGoal.containsKey(id)) {
                    buildNewPath(id, control, this);
                }
            }
        });
        return path;
    }

    //Part where it seam to have an issue on the last wayPoint.
    //This is where the new MotionPath is build and set.
    private boolean buildNewPath(EntityId id, MotionEvent motionControl, MotionPathListener listeners) {
        boolean result = false;
        List<HexCoordinate> newPath = getPathfinderPath(
                new HexCoordinate(motionControl.getPath().getWayPoint(motionControl.getCurrentWayPoint() + 1)),
                movementUpdateGoal.get(id));
        if (newPath != null) {
            motionControl.stop();
            motionControl.getPath().disableDebugShape();
            MotionPath newMotion = buildPath(motionControl.getSpatial().getLocalTranslation(), newPath);
            motionControl.setPath(newMotion);
            motionControl.setInitialDuration(ms * (newPath.size() + 1));
            if (listeners != null) {
                newMotion.addListener(listeners);
            } else {
                addPathListener(id, newMotion);
            }
            movementGoal.put(id, movementUpdateGoal.get(id));
            motionControl.play();
            result = true;
        } else if (movementGoal.containsKey(id)) {
            entityData.setComponent(id, new MoveToComponent(movementGoal.get(id)));
        }
        movementUpdateGoal.remove(id);
        return result;
    }

Thanks in advance for any help.
Ps : I’ve tryed to keep only the needed code, if more is needed i can upload the whole file.