How do call function from indiect pointer to USTRUCT() ?

First I get pointer to struct like this (since I don’t know name of struct property, only it’s type):

    FGAAttributeBase* UGAAttributesBase::GetAttribute(const FGAAttribute& Name)
    	UStructProperty* tempStruct = FindField<UStructProperty>(this->GetClass(), Name.AttributeName);
    	FGAAttributeBase* attr = nullptr;
    	if (tempStruct)
    		attr = tempStruct->ContainerPtrToValuePtr<FGAAttributeBase>(this);
    		return attr;
    	return attr;

And then I try call function on it to set value.

		FGAAttributeBase* attr = this->DefaultAttributes->GetAttribute(eval.Attribute);
		float newValue = 0;
		if (attr)
			if (HandleIn.IsValid())
				attr->AddBonus(FGAModifier(eval.Mod, eval.Value), HandleIn);
				//DefaultAttributes->SetAttribute(eval.Attribute, attr);

This doesn’t work. I assume that this:


Returns not pointer to actually struct, but pointer to copy of value of struct.

Is there any easy, way of getting pointer to struct (by only knowing it’s name), and then calling function on it ?

bump. Anyone ?

I had a look at this when you first posted, started to write something and then decided it was way above my head. I guess I’m not 100% sure what it is you want to do. Maybe if you added the code for the declarations of your types (UGAAttributesBase, FGAAttribute, FGAAttributeBase) so the relationship between them is clear, it might make your intention clearer.

UGAAttributeBase is to big to post it here, but beyond that one function it doesn’t have any particular relevance here.

FGAAttributeBase is struct containg information about attribute (BaseValue, CurrentValue, Values of modifiers).

FGAttribute have single property called Name (;.

In any case I think I have figured out solution, I could access properties indirectly, since I should be able to find any UPROPERTY() inside USTRUCT(), I can get it’s numeric value and set it.

Though, this case will require performing at very least 2 searches (find struct, find property inside struct).

I had a little look through the engine code, and honestly it looks like what you are doing should work to me. If you check the implementation of UProperty::ContainerPtrToValuePtrInternal, it’s just adding on the byte offset of the property to the pointer to the outer UCLASS object that you give it. So I’d expect you’d end up with a casted direct pointer to the struct property. Did you check that the FindField call is returning what you’re after? You didn’y say in what way this isn’t working, so it’s hard to say more.

And it work. But only on primitive properties like float, int etc (and for that matter only those exposed to reflection).

What I tried to is to set properties inside what you can call complex property (like struct).
And I think in this case I simply don’t get an point to struct I pointer to copy of my struct, and I set value in this copy.

Also you must consider there is special function is used to set numeric properties
UNumericProperty::SetFloatingPointPropertyValue(pointer, value).

But as far as I can see there is build in engine easy way to simply change values inside struct.

In the end is not that much of a big deal.

But presumably what you suggested above, iterating over the child properties, allows this? Attempting to call a method and accessing a non-UPROPERTY member are things that you should not expect to be exposed by the engine, since they’re not reflected. Any way of doing it would be to some extent a bit of a hack I think.

Ah no I never said I will try to call it on non UPROPERTY().

There are obviously some non UPROPERTY() properties inside struct, and I will need to change them of course.