Can Nested Struct Properties like FTransform be edited by ValuePtr?

Lets say I have an FTransform UProperty on a Uobject.

Let’s also say I want to be able to find the property by name and change just the X value of the Translation struct within the FTransform.

I already know it’s possible to change a struct such as an FVector that is a top level UProperty on a UObject like so

UObject* Target;  //Lets assume this is a valid UObject
FStructProperty* CurrentStruct = FindFProperty<FStructProperty>(Target->GetClass(), TEXT("X"));
	if (!CurrentStruct)
	{
		return false;
	}

	void* StructAddr = CurrentStruct->ContainerPtrToValuePtr<void>(Target);

	FProperty* NestedProp = CurrentStruct->Struct->FindPropertyByName(TEXT("X"));
	if(!NestedProp)
	{
		return false;
	}
	FFloatProperty* NestedFloatProp = CastField<FFloatProperty>(NestedProp);
	if(!NestedFloatProp)
	{
		return false;
	}
	void* ValueAddr = NestedFloatProp->ContainerPtrToValuePtr<void>(StructAddr);
	//void* ValueAddr = (uint8*)StructAddr + NestedFloatProp->GetOffset_ForInternal(); 
	NestedFloatProp->SetFloatingPointPropertyValue(ValueAddr, InValue);

This works because the outer of FVector is a Uobject*

In the case of FTransform - the outer is only a valid UObject* for the FTransform and not the struct within it called Translation.

Is it possible change a single property by name - that is nested within a struct, such that its Outer’s is not a UObject?

Using the Property system, you’d need to get the value, change it, and then set it again. This is similar to how Blueprint needs a “break structure” node to update a struct property.

That being said – you’re in C++. You can define an interface or object base class that has a property you can access as a C++ object, rather than through the property system. Get pointer to containing object, update field.X, done! It’ll also run a lot faster than going through properties.

1 Like

Thanks for the reply. I’m trying to leverage the property system so I can dynamically find the exposed values of a UClass - and link them to data coming from a network interface that isn’t compatible with Remote Control plugin from Epic.

As you said a static approach using just c++ ptr to a UObject is much faster but it doesn’t offer the flexibility I’m looking for. With the property system I can find all the exposed UProperties dynamically on any UObject. Is there a better way to dynamically link something like incoming network data to a UProperty?

To be clear - I’m creating a user defined linkage, which is why finding and settings the property by name needs to be dynamic in some way. I’ll have to be able to query a UObject for all it’s exposed properties.

All I’ve been able to find so far is leveraging the property system, but thats straying away from the original question.

If you’re doing something like receiving DIS PDU packets, and trying to render objects in the world, then there are several better options.

First, Actors have a known location/orientation. Instead of using UObject, you could say that anything driven by your incoming packets is an AActor, which lets you use direct pointers.

Second, you could implement a custom interface, and query for that interface, and then send whatever update you need through that interface. Something like IUpdateReceiver and have it have a ReceiveUpdatePacket method, if the structure of the packet is known.

That being said – if the abstraction penalty isn’t a big problem for you, that is indeed a very decoupled approach. In that case, get the struct value, update the value, and set the struct value again.

1 Like

Thanks for your insight. There might be some combination of an Interface and a known message structure that could work for all the knowns - but can always default on the property system if it has to. This was very fast very excellent information. I’ll mark it as resolved as soon as I can get it working.

Thank you!