Im making a game where the units are instances of a instanced static mesh component.
Thats the only physical representation they have in the world.
They have no collision because the game is tile based and its 2d.
So I identify where the units are by the tile.
The only thing i need, is the data for the units.
Their location is also stored in the instance of the instanced static mesh component as is.
Im conflicted because i have been receiving different and opposing suggestions.
I was about to do a struct + the instance. Experienced unreal users said that is a good idea, saying there is no reason to use AActor in this context, others dont really like the idea of not doing this in anything but actors, even uobject they say its not a good idea. Though it left me with the impression that not all understood the context, or that i didn’t explain it well.
So I started with the hardest hypothesis. The struct + ism.
I created one actor that includes all the units as instances of one instanced static mesh component.
So all units physical representation are part of this ISM component.
Then i created the struct that is the data of the unit. With its health, the current tile, the checkpoints for the movement, etc…
I tried moving it and everything seems to be working for now.
Though i came accross some things that perhaps for not being used to them make me hesitant in pursuing with this…
Im afraid something down the line might make this system a bad idea.
And from my searches i gathered that UStructs COULD be worse in this context for these reasons, though there could be many more:
-
Replication (I dont have experience with unreal multiplayer system though i made multiplayer games in the past). Though this is not supposed to be multiplayer.
-
It is not garbage collected. Though it seems you can just store the unit data struct in an array, and just removing it from the array when the unit dies will just work. *
-
UStruct is bad in blueprints. Though i dont intend to use blueprints a lot.
-
*Combat : When 2 units are fighting, unit A vs Unit B. Unit B will get the struct pointer of unit A, and start combat. If unit A dies. I remove unit instance and remove its corresponding struct from the array of structs. Though the pointer seems to stay alive in the Enemies. Whereas an actor seems that it would fix that automatically, and using IsValid would also give a safety net. With structs i would have to clear also this pointer and any other enemies pointer engaging this unit. Sounds that this could be problematic but also a good exercise.
Anyways. I halted all work, and dont know what to do. I’m with decision paralysis. And dont want to program the whole thing as actors only to have to change it to Struct later.
What should i do in this context?
Edit:
After making some more research, I came accross this reddit post comment:
That mentions Data Asset struct.
With this one i could have functions in my class, and could use UFUNCTION for returning pointers of struct. Is suitable for blueprints, etc…