Everything is set up perfectly! In the Inspector for “Party” I have set 1 for the Member List and attached the gameObject with “Player” script into it. In my HUD inspector I attached the Party GO with Party script in it. I don’t get why it’s not finding the reference. I’m getting the error code on the line “player.Add(party.Member[0].GetComponent()”. I don’t get it, Member[0] has my player attached, and my player has a Player script attached, where am I going wrong?
public class Party : MonoBehaviour {
public List<GameObject> Member = new List<GameObject>();
}
public class BattleHUD : MonoBehaviour {
public Party party;
private List<Player> player = new List<Player>();
public void LinkPlayers(){
player.Add (party.Member [0].GetComponent<Player>());
}
}
You haven’t constructed party or you have more than one object with that script.
Party party = new Party();
Why would I need to “Construct” party? It clearly shows in the inspector the Player attached to the list.
Currently I only have one player “activeInHierarchy” with the Player script. And why would it matter if I had two or more? I’m referencing to the List index 0 so shouldn’t the call look there?
Strangely… This error is a bug… I switched the private List player to public List player and the error pops up, but there in the List is sitting the player script I was trying to “get”.
Soo… yea
So the same thing happened with my Enemy list and I figured out it was because I hadn’t added the
= new List(); when initializing the list… But also that itself didn’t fix it, I had to switch to public then private again.
or maybe I didn’t notice that adding the = new List(); part fixed it the first time because such a similar error with the Enemy list popped up and I thought it was the same error >_>