A* Pathfinding Project

Weird behaviour when adding RVOSimulator with AddComponent


#1

Hi Aron,

I’m noticing weird behaviour when I’m adding an RVOSimulator component to a gameobject in Awake. The AI seem to just walk back and fourth like this:

ai_bug_2

Setup is like following:

using Pathfinding.RVO;
using UnityEngine;

public class RVOSimulatorWrapper : MonoBehaviour 
{
	private RVOSimulator simulator;

	private void Awake()
	{
		Initialize();
	}

	public void Initialize()
	{
		if (GetComponent<RVOSimulator>() != null)
		{
			return;
		}

		simulator = gameObject.AddComponent<RVOSimulator>();
		simulator.desiredSimulationFPS = 30;
		simulator.movementPlane = MovementPlane.XY;
	}
}

Also, in order for this to work I need to put the script execution order for the RVOSimulatorWrapper before all the stuff under the Pathfinding namespace, otherwise agents in the scene wouldn’t be able to find an RVOSimulator.

Is this a bug, or am I missing something ?


#2

Hi

Which version are you using?
It looks like the RVOSimulator gets configured for the XZ plane. Probably it does some initialization during Awake in your version.
In the current beta it should work I think.
As a workaround you could always just instantiate a prefab instead of adding the component using code.


#3

I’m using 4.2.10. The latest from the asset store.

The workaround with instantiating a prefab seems to work, so we’ll use that for now. Thanks Aron!