Download

Library classes inheriting from UObject

I’m make a pretty data-heavy game, and I find myself needing a boatload of classes whose only real job is to store structs; character data, item information, and so forth. Nobody will ever instantiate these classes in the world, their only job is to be #included by other stuff that needs to use their structs. I want replication and garbage collection, which means they need to be a child of UObject, but is there a “correct” class I should be specifically inheriting from? I’ve been using AActor, but that seems like a wasteful choice when you consider that they don’t actually enter the world.

UObject is a nice choice for this, you can replicate it but you need an Actor.
For example, for your Items, you can create a PlayerState, make an UItem (who can be replicate, use this topic : https://forums.unrealengine.com/showthread.php?59275-Replicating-TArrays-crashes-game&p=231425#post231425) and use your TArray<UItem*> as Inventory in your PlayerState, it’s a simple setup but it work, make it better when you understand all the replication stuff :slight_smile:

Also, read this topic to store your data, Singleton Class is really nice to do this : https://wiki.unrealengine.com/Global_Data_Access,_Data_Storage_Class_Accessible_From_Any_CPP_or_BP_Class_During_Runtime

I hope this help you ! :slight_smile:

This is super-helpful, thank you for the recommendations and the further reading! :slight_smile: