A is affecting B and I don't know how

Hiya,
So it’s been a while since I’ve posted and I’m going to try to fill in as much relevant information as possible. In all honesty i don’t know whats going to be needed so I might put to much or to little here.

Let me start by explaining what I have and what is going on in my game. I have two bases (A B). Within each base’s control script there is a custom class which holds all the basic stats of any minion that base creates. The base creates a minion and in doing so sends that stats list to the minion for construction. The minions stats now have those numbers. The minion starts going off to do whatever command I’ve given it. All that works great. The thing I don’t get is when the minion takes damage the damage is also being applied to the Statslist of the base that created that minion. So if a minion gets created with two wounds and takes two wounds the minion dies, but the two wounds are also being applied to the base that created it. Subsequently all further units created by that base would have a wound count of 0. As more units are skirmishing their initial wound counters go further and further into the negatives.

Other than when a unit is created the base and the minion have no connection to each other that I can find. I have no clue how the negative to the wound is being applied to the base. I’m guessing this is not enough to find the problem but in all honesty I have no clue where to look. Any code the internet might need to help me figure this out I can happily provide.

Custom class for minion stats

[System.Serializable]
public class Statslist {

    public int movementSpeed, attackSpeed, swings, evade, power, toughness, wounds;
}

Base control script, the ‘commands’ is a variable I set up that points to the minions control script so I don’t have to keep typing it out.

public Statslist builtMinionStats;
....
public void createMinion(){
...
		//Generic Stats
		commands.Construct(controllingPlayer, builtMinionStats);
....

Minion control script

    public Statslist minionStats;
....
    //Build stats
    public void Construct(int sentControllingPlayer, Statslist sentStats){
        controllingPlayer = sentControllingPlayer;
        minionStats = sentStats;
    }

    public void Wounded(){
        minionStats.wounds--;
        if(minionStats.wounds<=0  dieing==false){
            dieing=true;
            Death();
        }        
    }

One thing I just noticed was that even existing minions created from the same base change their stats, not just new minions

The StatsList is most likely a Class? If so it’s being passed by reference instead of value, which means that everyone is sharing a reference to the same StatsList as opposed to each getting their own copy of the StatsList.

Hope that helps!

Oh I think I get it. So being I putting all my stats into a class I made called “Statslist” (which makes it nice because I can simply collapse everything) and use that whole class as one argument I’m actually make a reference between the base’s stats and every minions stats. They are all sharing the same reference. And it doesn’t look like I can change that reference into a value so I have to send each stat as it’s own argument.

I’ll figure this out sooner or later.

You don’t have to send each stat as its own argument, you just need to make new StatsList objects and copy the values over.

You might potentially get away with turning StatsList into a Struct instead of a Class. Structs are passed by value, which means that they’re copied rather than referenced.