Hey all,
I’ve current got an array of structs, and when the user deletes one of these structs in the editor, I want to get some properties from off the struct before it’s destroyed.
I’ve attempted using virtual void PreEditChange(FProperty* PropertyAboutToChange) override, although it doesn’t provide any method to find the index of the element being deleted, nor to retrieve the properties, or the overload with the FEditPropertyChain& parameter in place of the FProperty*, but again there’s nothing I can find for either getting the index of the element, or the properties I need…
And of course by the time we reach PostEditChangeChainProperty which provides everything I need, the element has already been destroyed…
Any ideas?
I couldn’t get to capture the exact moment of deletion of the element on the array but I found a way for you to still know which element was deleted from the array.
The fallowing code was tested in Unreal4.24 with an array of custom structures.
std::vector<FEmojiMappingsValue> TempCopy;
virtual void PreEditChange(UProperty* PropertyAboutToChange) override {
Super::PreEditChange(PropertyAboutToChange);
const FString PropertyName = PropertyAboutToChange->GetName();
if ( PropertyName == TEXT("TestStructs") ) {
TempCopy.clear();
if ( UArrayProperty* p = CastChecked<UArrayProperty>(PropertyAboutToChange) ) {
TArray<FEmojiMappingsValue>* v = p->ContainerPtrToValuePtr<TArray<FEmojiMappingsValue>>(this);
TempCopy.reserve(v->Num());
std::for_each(v->begin(), v->end(), [&](FEmojiMappingsValue value) { TempCopy.push_back(value); });
}
}
}
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override {
Super::PostEditChangeProperty(PropertyChangedEvent);
if ( PropertyChangedEvent.Property ) {
const FString& PropertyName = PropertyChangedEvent.Property->GetFName().ToString();
if ( PropertyName == "TestStructs" ) {
if ( UArrayProperty* p = CastChecked<UArrayProperty>(PropertyChangedEvent.Property) ) {
TArray<FEmojiMappingsValue>* v = p->ContainerPtrToValuePtr<TArray<FEmojiMappingsValue>>(this);
std::for_each(TempCopy.begin(), TempCopy.end(), [&](FEmojiMappingsValue value) {
if ( !v->Contains(value) ) {
UE_LOG(LogTemp, Warning, TEXT("Property Deleted with values (%s,%s)"), *value.EmojiName, *value.EmojiCode);
}
});
TempCopy.clear();
}
}
}
}
Brilliant, tested this on 4.26 - had to make some minor changes such as changing all the UProperty’s to FProperty’s on the behest of my IDE, but it all works. Thanks!