DataRegistry polymorphic types

Hello,

DataRegistry.h holds several hints that it should be possible to have data of different types in same registry (specifically subclasses of the registry’s ItemStruct) (e.g. this comment from the file)

/** Returns the struct used by this registry, everything returned will be this or a subclass */ const UScriptStruct* GetItemStruct() const;Furthermore GetCachedItemRaw has OutItemStruct output parameter, which suggest that it contains the type of the ItemStruct returned, and also template <class T>const T* GetCachedItem seems to support retrieving items of subclassed types.

However, GetCachedItemRaw (actually all functions that have OutItemStruct output parameter) ALWAYS just set the OutItemStruct to the DataRegistry’s ItemStruct

OutItemStruct = GetItemStruct();It seems to me that the function template <class T>const T* GetCachedItem can actually never work with any other template parameter than the registry’s ItemStruct (the ensureMsgf will always fail for anything else, as TempItemStuct will always be the registry’s ItemStruct and nothing else).

Am I missing something here? Is there a way to use this feature in the current version? Or is it a planned feature that doesn’t work yet?

Hello Martin,

The current version of the DataRegistry is mostly a wrapper for DataTables and CurveTables which only support fixed types and no subclassing. The API supports other types of more dynamic sources, but you would need to implement them yourself. Internally we have some source types that are close-to-datatables but not exactly the same which does work well, but they are also not polymorphic. The original design included plans for truly dynamic sources like databases, but we have not implemented that internally and it would probably need some additional fixes. The AcquireItem flow is not fully fleshed out.

But for this case fixing the API to support basic type changing shouldn’t be that hard, I believe OutItemStruct just needs to be set to FoundCache->GetItemStruct. I believe GetCachedItem would then work properly. It might need a few more fixes, as I have not tried this myself. But it does seem reasonable, and if you can get it to work you can either submit a Pull Request if it took more work, or just report back here I and I can fix GetCachedItemRaw