RVOController doesn't work until properties edited through inspector

I add RVOController at runtime.

if (RVOSimulator.active != null)
	{
			rvoController = Utility_Common.CreateOrGetComponent<Pathfinding.RVO.RVOController>(gameObject, out isNew);
			UpdateRVOController();
	}

void UpdateRVOController()
	{
		if (rvoController != null)
		{
			int myTeam = Team;
			// 2 is to skip DefaultAgent = 1 << 0, DefaultObstacle = 1 << 1,
			if (myTeam < 0)
			{
				rvoController.layer = Pathfinding.RVO.RVOLayer.DefaultAgent;
				rvoController.collidesWith = (Pathfinding.RVO.RVOLayer)(-1);
			}
			else
			{
				rvoController.layer = (Pathfinding.RVO.RVOLayer)(1 << (myTeam + 2));
				//rvoController.collidesWith = (Pathfinding.RVO.RVOLayer)(IGameSystem.Instance.GetTeamManager().GetFriendlyMask(myTeam) << (2));
				rvoController.collidesWith = (Pathfinding.RVO.RVOLayer)(-1);
			}
		}
	}

For testing, I set collides with to Everything and the radius to a large value in order to force the units to spread apart. You can see from this screenshot it doesn’t work

Run again, in the inspector set radius to 2.401 instead of 2.4.

As soon as I do that the bunched up units spread out

A* Pathfinding Project Version: PathfindingProject_Pro_WebsiteDownload_4_2_8_4262b723
Unity Version: 2019.1.8f1

Bump. Any idea on this?

Hi

I have not been able to replicate this. Furthermore I have checked the editor scripts and I cannot see any updates that are triggered by the inspector being edited. Do you think you could post a video of this happening and/or a test project in which I could replicate the bug?

Video:

I’m running into the same issue. Here’s a video: https://drive.google.com/file/d/15McnYCzkOhL-aTikK3aHzAZ13FKx65N4/view

With all components already attached to the prefab, it’s working fine. But removing the components and adding them in Awake with the exact same settings, will cause RVO to not work. Selecting an agent with the scene view open will somehow make RVO for that agent work again.

I’ve also uploaded this example project. You’ll need to add the A* package manually (I’ve used PathfindingProject_Pro_WebsiteDownload_4_2_8_4262b723.zip). The example project can be found here: https://drive.google.com/open?id=19s45u5lNAMC9CD8S4ncbU99vgXZEMSEY

Ah. Are you @Kevin_Jenkins also adding the components during Awake/Start or later?

So the reason that happens is because the AIPath script looks for any attached RVOControllers when the component is enabled. If it cannot find it then it will not look for it again later due to performance reasons. Looking for it every frame would be very expensive, and there is no event so that the script can get notified about new components that are attached. I’d recommend disabling the AIPath component and enabling it again after you have attached the RVOController so that it will pick it up.

However since people often attach/detach components manually using the unity inspector it is nice if those are picked up by the script immediately. Therefore the AIPath script will look for attached components every frame if it is selected in the scene view. This is why it started working when you selected it.

AddComponent<RVOController>();
var ai = GetComponent<AIPath>();
ai.enabled = false;
ai.enabled = true;

In my dev version I have now added a change so that if an RVOController is attached during runtime it will notify the AIPath script that it should look for components again.

1 Like

That is correct. To fix the issue now, to clarify you are saying enable and disable AIPath after adding RVOController?

Yes. That is correct.