UE5.4 Learning Agents can't be use in C++

I created the LearningAgentsManager in C++, but modified MaxAgentNum after inheriting the blueprint, which resulted in the smart addition of an agent



This is always 1

In CreateDefaultSubobject, the component PostInitProperties have been executed, but the value of MaxAgentNum has not been loaded

@Deathcalibur

1 Like

This is a bug on the 5.4 version which has been corrected on the main branch in GitHub.

All the code in “PostInitProperties” should have been called instead during “OnRegister” like:

void ULearningAgentsManager::OnRegister()
{
	Super::OnRegister();

	// Pre-populate the vacant ids
	OnEventAgentIds.Reserve(MaxAgentNum);
	OccupiedAgentIds.Reserve(MaxAgentNum);
	VacantAgentIds.Reserve(MaxAgentNum);
	Agents.Reserve(MaxAgentNum);
	for (int32 AgentId = MaxAgentNum - 1; AgentId >= 0; AgentId--)
	{
		VacantAgentIds.Push(AgentId);
		Agents.Add(nullptr);
	}

	UpdateAgentSets();
}

Perhaps you can adjust this locally and your issue will be resolved!

Brendan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.