Hi all,
time came to optimize my game a bit since instantiate/destroy calls are making a lot of GC calls and it's about time to address that.
I was happy when nested prefabs came, but in the long run, it creates more problems when you intend on pooling stuff (which is neccessary for my game) since only the parent is pooled, all the children belonging to it are instantiated as usual.
I have two issues to address.
Issue #1Enemies have multiple children which have their exact default local position and their default state (active/not active). So, for the enemy of type Provoker (in the image below) i have the following:
Enemy Name: Provoker
Child 1: Light
Child 2: Light2
Child 3: ProvokerGunpoint
Child 4: JetAnimation
Child 5: EnemyTag
Child 1 Position: x, y, z
Child 2 Position: x, y, z
Child 3 Position: x, y, z
Child 4 Position: x, y, z
Child 5 Position: x, y, z
Child 1 State: Active/Not Active
Child 2 State: Active/Not Active
Child 3 State: Active/Not Active
Child 4 State: Active/Not Active
Child 5 State: Active/Not Active
So when i spawn the enemy named provoker, fsm on it should get it's name and then spawn children with appropriate position and state.
Issue #2Second issue is similar to first. Squadrons are groups of enemies which i handled relatively easy with nested prefabs, i just dragged and dropped prefabs, saved them under SquadronNameX prefab and that's it. But, unfortunately, these need to be spawned so using nested prefabs is kinda off.
So i meant of collecting all the data i need (which will be a long and tedious process by itself) and then what? I can store them in some data structure, but i don't know what would be the most suitable, internal like arraylist or external in a script.
The way i'm doing things now is horrible since i have few hundred of these with 5-10 enemies in each. First i need to spawn all enemies one by one and assign a variable for them
Then i need to manually set position for each one of them
It's tedious to do and there's A LOT of space for error. The preferred way would be a structure to draw data from, like get name of the squadron > number of enemies, if name of Squadron is NameX, spawn prefabY, assign positionZ, repeat until finished.
What can you recommend? Hash tables, arrays, huge scriptable object, json, xml? I'm quite confident in scripting lately, for the first time i see this maybe more viable in script then with fsms, bit i'd like to stick to fsms completely if possible.
P.S.
Not to mention that maintaining the other enemy systems with their data (HP, speed, loot and so on) is beginning to feel real tiresome by using local (per fsm) data, i'd like to organize that a bit better too.
There's some assets like bg database and gamedata editor, i guess they're worth checking out...