Can't seem to get object's property value from TIterator property

I’m iterating through an object’s properties, storing them in a TArray<FString> by name and at the same time storing the associated value in a TArray<float>.
However, I’m getting this output using my UE_LOG feedback:
[2015.06.02-18.56.58:990][153]LogTemp:Warning: Getting float property from GravityMagnitudeDuringGlide, value is -107374176.000000:
[2015.06.02-18.56.58:990][153]LogTemp:Warning: Getting float property from GravityCap, value is -107374176.000000:
[2015.06.02-18.56.58:991][153]LogTemp:Warning: Getting float property from FlapHoldTimeUntilGlide, value is -107374176.000000:

[2015.06.02-18.56.58:999][153]LogTemp:Warning: Reading back property names from TArrays, Property:GravityMagnitudeDuringGlide, Value: -107374176.000000
[2015.06.02-18.56.58:999][153]LogTemp:Warning: Reading back property names from TArrays, Property:GravityCap, Value: -107374176.000000
[2015.06.02-18.56.58:999][153]LogTemp:Warning: Reading back property names from TArrays, Property:FlapHoldTimeUntilGlide, Value: -107374176.000000

So I know the TArray emplace is working fine, except the float looks like an uninitialized(?) value…

I tried it in the object initializer, postinitializer, I tried it using ThisLevel->bIsVisible as a condition inside the tick and it always returns the same values, so I’m guessing there’s something I’m missing here.

Anyway, this is my code:



void AtwinStickPawn::GetObjectPropertyFloatValuesAndNames( UObject* Object )
{
	FString FObjectName = Object->GetName();
	
	UE_LOG( LogTemp , Warning , TEXT( "Getting float properties from %s"), *FObjectName  );
	
	int ForLoopCounter = 0;
	
	for (TFieldIterator<UFloatProperty> Property( Object->GetClass() ); Property; ++Property)
	{
		uint32 IndexPosition = ForLoopCounter;
		uint32 SizeOfUint32 = sizeof( uint32 );
		bool Result = ForLoopCounter <= MAXUINT32;
		check( Result );

		float VariableValue;
		Property->GetFloatingPointPropertyValue( &VariableValue );

		FString VariableName = Property->GetNameCPP();
		ThisObjectFloatPropertyNames.Emplace(VariableName);
		ThisObjectFloatValuesByIndex.Emplace( VariableValue );
		UE_LOG( LogTemp , Warning , TEXT( "Getting float property from %s, value is %f:" ) , *VariableName, VariableValue );
		ForLoopCounter++;
		
	}
	for (uint32 i = 0; i < ((uint32)ThisObjectFloatPropertyNames.Num()); i++)
	{
		UE_LOG( LogTemp , Warning , TEXT( "Reading back property names from TArrays, Property:%s, Value: %f" ) , *ThisObjectFloatPropertyNames* , ThisObjectFloatValuesByIndex*);
	}

}



Thanks!

Ah ok, looks like I found out the proper way to do it, although I don’t fully understand why.
If anyone can explain this to me, that’d be awesome.

My GUESS is that value is actually the name of the property…? I’ll have to do some reading on containers.

The problematic bit was


Property->GetFloatingPointPropertyValue( &VariableValue );

The correct way is:


VariableValue = Property->GetPropertyValue_InContainer( Object );

I’d love to hear any insight about why this worked as opposed to the first attempt.

Thanks!

Ah it appears that there was never an object instance to get the property values properly from. It would have been using offsets from essentially garbage addresses in this case.

1 Like