I have the Problem that when I call the AddSkill void it is called properly but it doesn’t add the skill to the Skills list.
Here is My code:
public List<Skill> Skills = new List<Skill>();
private SkillDatabase skillDatabase;
void Start ()
{
skillDatabase = GameObject.FindGameObjectWithTag("Skill Database").GetComponent<SkillDatabase>();
AddSkill (1);
AddSkill (2);
AddSkill (3);
}
private void AddSkill (int id)
{
print ("AddSkill called");
for (int j = 0; j < skillDatabase.skills.Count; j++)
{
print ("Skill number" + j);
if (skillDatabase.skills [j].skillID == id)
{
print ("Skill added: " + skillDatabase.skills[j].skillName);
Skills.Add(skillDatabase.skills[j]);
}
}
}
First of all, if you ask me, I’d suggest you use a Dictionary instead of a list. Much easier to get the corresponding skill like so: Skills[“Survival 1”]. No need to manually iterate through the list and find the right Id. Dictionaries are build to optimize these kind of “Here’s the key, gimme my value” process.
I’d go like this:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SkillDatabase : MonoBehaviour {
public Dictionary<string, Skill> skills = new Dictionary<string, Skill>();
void Start()
{
//skills.Add(new Skill(name, ID, pointsNeeded, stageNeeded, description, skill.skilltype.type, known))
skills.Add("Survival 1", new Skill("Survival 1", 1, 1, 0, "Basic Survival - You don't get
hungry/thirsty that much anymore
and you are less likely ill
- needed for Survival-Skills of stage 1", Skill.SkillType.Survival, false));
skills.Add(“Survival 2”, new Skill(“Survival 2”, 2, 2, 1, "Basic Survival - You don’t get
hungry/thirsty that much anymore
and you are less likely ill
- needed for Survival-Skills of stage 2", Skill.SkillType.Survival, false));
skills.Add(“Survival 3”, new Skill(“Survival 3”, 3, 3, 2, "Basic Survival - You don’t get
hungry/thirsty that much anymore
and you are less likely ill
- needed for Survival-Skills of stage 3", Skill.SkillType.Survival, false));
}
}
And then use it like so:
public List<Skill> Skills = new List<Skill>();
private SkillDatabase skillDatabase;
void Start ()
{
skillDatabase = GameObject.FindGameObjectWithTag("Skill Database").GetComponent<SkillDatabase>();
AddSkill ("Survival 1");
AddSkill ("Survival 2");
AddSkill ("Survival 3");
}
private void AddSkill (string name)
{
print ("AddSkill called");
// Make sure that the skill actually exists:
if (skillDatabase.skills.ContainsKey(name))
{
Skills.Add(skillDatabase.skills[name]);
}
}
Now, that doesn’t actually answer your question, so after my humble opinion, if you still want to use your version with the List, I’d like to know if the “print” lines are fireing, if so with what results 
It didn’t work either but I discovered that it was because of the scriptexecutionorder