Using FollowerEntity without movement

  • A* version: 5.3.7
  • Unity version: 6000.1.1f1

Hello,

I would like to use the FollwerEntity component, but without letting it move the character by itself. Instead, i would like to retreive the desired direction each frame to manage the movement with another component.

I have disabled the tag, and tested the code with LocalAvoidance2D demo scene.

_follower = GetComponent<FollowerEntity>();

if (_follower == null)
       return;

World world = World.DefaultGameObjectInjectionWorld;
_entityManager = world.EntityManager;

_entity = _follower.entity;

if (_entityManager.HasComponent<SimulateMovementFinalize>(_entity))
      _entityManager.RemoveComponent<SimulateMovementFinalize>(_entity);

It seems to work fine. Then I tried to find a way to get a vector to make my gameobject move manually every frame with the following code :

With desiredVelocity :

direction = _followerEntity.desiredVelocity.normalized
_characterMovement.SetMovement(direction);

With steeringTarget:

 direction = (_followerEntity.steeringTarget - transform.position).normalized;
_characterMovement.SetMovement(direction);

DesiredVelocity doesn’t seem to be relevent. I tryed other solution like using the steeringTarget or managing the movement with the waypoints of the vectorPath array, but no solution give the expected result. I feel bad because the solution should be really simple to get. And I think that this solution will interest a lot of people because it gives the ability to use the FollowerEntity like a computation class, and not necessarly like a movement script which give the ability to integrate in architectures that required to manage the movement with another class.

Thank you fo your help.

Regards,

A response for the previous post was given in this thread:

Hi,

Thank you for your replay. This solution is suppose to work according to the class documentation. I tested it in the LocalAvoidance2D demo, but it doens’t work. Here is the code I used to realise the test :

using Pathfinding;
using Pathfinding.ECS;
using Unity.Entities;
using UnityEngine;

public class DisableFinalizeMovement : MonoBehaviour
{
    private FollowerEntity _follower;
    private EntityManager _entityManager;
    private Entity _entity;

    void Start()
    {
        _follower = GetComponent<FollowerEntity>();

        if (_follower == null)
            return;

        World world = World.DefaultGameObjectInjectionWorld;
        _entityManager = world.EntityManager;

        _entity = _follower.entity;

        if (_entityManager.HasComponent<SimulateMovementFinalize>(_entity))
        {
            _entityManager.RemoveComponent<SimulateMovementFinalize>(_entity);
        }

    }

    void Update()
    {
        //Debug.Log("Solution 1 : " + _follower.desiredVelocity);
        Debug.Log("Solution 2 : " + _entityManager.GetComponentData<ResolvedMovement>(_follower.entity).targetPoint);
    }
}

To test it, I removed 8 robots entities to keep 2 of them. On the first, i added my component.

When I launch the game and I click, the second robot moves to the correct point. The first one doesn’t move, and the console messages doesn’t give the correct information.

The orange gizmos update correctly, so I guess the internal mecanism knows where to go. I can move the character by using the vectorPath , but i won’t benefit from the local avoidance, nor the off mesh links capabilities.

Regards,

Thanks for spinning up a new thread on this, it’s appreciated. This may be one I’ll need clarification on from Aron, since ECS is one of my personal weakspots (getting better! :upside_down_face: sorry for all the tags today @aron_granberg)

1 Like