Hi there,
I am working on a typical game, where you control a Pawn/Character and your PlayerController would hold such data as Items, Money and a Stat-Configuration(e.g. stamina, health- or defense-upgrades with which the player would spawn the next time).
Usually like e.g. in Java/C#(Unity), I would try to encapsulate behaviour and variables as much as possible.
I would combine Items and Money into an “Inventory Class”, which should be further splitted into a “ItemManager Class” and “CurrencyManager Class”.
Stat-Configuration would receive a “Stat Class”.
The Playercontroller should possess the Inventory and Stat Class.
The Class names and what they do, do not matter much for me right now. What’s really important about this structure is the nesting of these classes.
Since normally at least for Blueprints you can of course attach ActorComponents to an Actor, but no ActorComponent to another ActorComponent like you would do with Actor & ActorComponent. You could add them as variables of course, but right now I don’t know how to spawn an ActorComponent in Blueprint and what changes would still be needed for proper replication.
The question is now: Of what type should these Classes(Inventory, Stat) be, to actually achieve this hierarchy and allow proper replication and RPC-Calls from within these classes:
My previous research:
Possible considerations are: Actor, UObject, ActorComponent
UObject:
- has the smallest size of all, (someone wrote something about 200 Bytes vs some KB for the Actor, but I don’t have the source Link for that anymore.)
- Replication of variables must be added manually (Replicating TArrays crashes game - Multiplayer & Networking - Unreal Engine Forums, A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums)
- RPC do not work at all from UObject (probably since UObjects don’t contain an owner/networkrole and such)
- would have no Role variable to check against (for ROLE_Authority, …), but that doesn’t matter since RPC aren’t even supported.
- RPC would have to be done in Actor/ActorComponent which owns this UObject which would be against the principle to encapsulate behaviour.
So to actually make this work with UObjects, you would be either constraint to only variable replication and no RPC from within the UObject or you would have to create your own “UNetworkedObject” to get RPC to work as well.
ActorComponent:
- Replication works
- RPC works.
- can get role via “GetOwnerRole()” from Actor.
Is nesting of ActorComponent towards another ActorComponent possible?
Actor:
- largest size of all
- contains a world position, which I don’t really need for Inventory or Stats
- would have it’s own Net-Priorities and so on,(which might cause trouble further on?)
Other statements I gathered:
- Somewhere (don’t have source anymore) a developer stated, that replication was meant as a flat hierarchy, so only one Actor and ActorComponents attached to that one Actor.
- Another one suggested to always use Actors for Networking and UObjects only if not network depended.
Okay, that were a lot of facts right now, but I just wanted to present you my current understanding of this topic.
So back to the question:
How did you handle more complex classes like this example?
I don’t really like the idea to actually create everything out of Actors or force my whole model into that flat hierarchy. My next try would be to nest ActorComponents.
Greetings,
smara