Search code examples
c#unity-game-enginegame-developmentunity3d-mirror

UNITY Looking for a way to store temporary global delta value for a specific spell


I am kind of new to unity and currently designing a spell architecture in a multi-player game that could make spell parameters vary with the environment(e.g. character, equipment, buffs, etc...).

Yes, it is a multi-player game and I am using Mirror as the multi-player service framework, which means I may consider these delta values as sync vars.

For example, I designed a fireball spell. The damage of this spell may increase because I could gain a buff. My idea is to use a scriptable object to store the basic parameter values of the spell(e.g. damage, spell radius, etc...), and then all delta values(e.g. damage increment) would be collected somewhere. This place should be exclusive to a player.

In this way, I can calculate the total damage by just adding all delta values on the basic damage stored in the scriptable object.

My question is where to store these delta values for every spell separately?

Is there a global way to store these delta values without instantiating an object?

I tried scriptable objects but as they are assets, maybe it is not a good idea to use them in this non-persistent scenario. I wish these delta values could be collected by GC when I do not need them.

I also tried to create scriptable objects at runtime but it doesn't work as well. I don't want to access these scriptable objects after instantiating the object, and scriptable objects no longer exist when the object is destroyed. I want these delta values could be in a global variable that accompanies the entire life cycle of the game. So I can keep firing fireballs that improve damage.

The character(hero) already have a temporary scriptable object to store delta values for all spell. But what if I only want to improve specific spell damage like fireball?

Or there actually is a better architecture to implement this spell system without storing delta values separately?

After @derHugo reminder(very much appreciate it), I found that I forgot to explain that this is a multiplayer game. A simple static class for all players may not solve this problem.


Solution

  • I found I can meet my need without storing delta spell parameters. They can be calculated dynamically by other SpellCalculator.

    If I insist, I can also store the delta spell parameters by dynamically creating ScriptableObject at run time. Obviously, this is unnecessary.