LearningAgents: Check triggered when making optional observation

Hi,

After upgrading to 5.5, we’ve noticed some checks firing on null optional observations. The checks appear to be attempting to enforce the RESTRICT qualifier on array inputs, but if the arrays are null, the check still gets tripped anyway, even though the loop gets skipped due to input/output sizes of 0. I’ve attached a sample repro based on the “Learn to Drive” sample that has a “UCrashyInteractor” that provides a minimal repro.

This is the interactor code that triggers the crash:

`// CrashyInteractor.cpp
#define OBSERVATION_1 FName(TEXT(“Observation_1”))
#define OBSERVATION_2 FName(TEXT(“Observation_2”))
#define OBSERVATION_3 FName(TEXT(“Observation_3”))

#define ACTION_1 FName(TEXT(“Action_1”))
#define ACTION_2 FName(TEXT(“Action_2”))

void UCrashyInteractor::SpecifyAgentObservation_Implementation(FLearningAgentsObservationSchemaElement& OutObservationSchemaElement, ULearningAgentsObservationSchema* InObservationSchema)
{
FLearningAgentsObservationSchemaElement Observation_1 = ULearningAgentsObservations::SpecifyStructObservationFromArrayViews(InObservationSchema,
{
OBSERVATION_1,
},
{
ULearningAgentsObservations::SpecifyBoolObservation(InObservationSchema, OBSERVATION_1),
});

OutObservationSchemaElement = ULearningAgentsObservations::SpecifyStructObservationFromArrayViews(InObservationSchema,
{
OBSERVATION_2,
OBSERVATION_3,
},
{
ULearningAgentsObservations::SpecifyOptionalObservation(InObservationSchema, Observation_1, 128, OBSERVATION_2),
ULearningAgentsObservations::SpecifyFloatObservation(InObservationSchema, 1.0f, OBSERVATION_3)
});
}

void UCrashyInteractor::GatherAgentObservation_Implementation(FLearningAgentsObservationObjectElement& OutObservationObjectElement, ULearningAgentsObservationObject* InObservationObject, const int32 AgentId)
{
OutObservationObjectElement = ULearningAgentsObservations::MakeStructObservationFromArrayViews(InObservationObject,
{
OBSERVATION_2,
OBSERVATION_3,
},
{
ULearningAgentsObservations::MakeOptionalNullObservation(InObservationObject, OBSERVATION_2),
ULearningAgentsObservations::MakeFloatObservation(InObservationObject, 1, OBSERVATION_3),
});
}`

Steps to Reproduce

  1. Open the project using Unreal Editor 5.5.4 (you may need to generate project files)
  2. Open the level VehicleAdvExampleMap
  3. Run PIE
  4. Observe the check

Hmm, I copied your sample interactor code into my local project and I’m unable to reproduce. This code seems to run just fine.

Perhaps it was magically fixed on Main.

Note that I did attach a sample project to repro this but I don’t see it in the attachments - let me know if I should reupload.

Ah yeah it looks like this was the commit that fixed it:

https://github.com/EpicGames/UnrealEngine/commit/3cd7bbd9e3ba769ab1915a22cf77a548c189731f

Thanks for taking a look! We switched to essentially the same check in our version of the engine, so it’s good to get confirmation that was the right approach.