The problem I have is that CreateInstance returns null.
Here is the code:
if(spattmono[0] != null)
{
if((SpecialAttack) System.Activator.CreateInstance(
spattmono[0].GetClass()) == null)
{
Debug.Log("DUMB ACTIVATOR!!!");
}
//combo.SetSpecialAttack(spattack);
}
Attack and SpecialAttack are both classes that store basic information, and inherit from UnityEngine.Object.
Attmono and spattmono are both MonoScript arrays, attmono being able to hold 16 and spattmono being able to hold 4.
They get there information from these.
for(int at = 0; at < numberOfAttacks; ++at )
{
attmono[at] = (MonoScript) EditorGUILayout.ObjectField(attmono[at],
typeof(MonoScript), false);
}
for(int spat = 0; spat < 4; ++spat )
{
spattmono[spat] = (MonoScript) EditorGUILayout.ObjectField(
spattmono[spat], typeof(MonoScript), false);
}
You could think of MonoScript just as something that holds what class type the object is.
I have checked each of these with Debug.Print statements and both are not null when being assigned.
Here is the SpecialAttack code.
public class SpecialAttack : UnityEngine.Object
{
public string Name;
public int Damage;
public int Force;
public float Cooldown;
public SpecialAttack()
{ }
public virtual bool Run()
{
return false;
}
}
Ive recently tested this
if((SpecialAttack)System.Activator.CreateInstance(spattack.GetType()) == null)
{
Debug.Log("DUMB ACTIVATOR!!!");
}
And it was indeed null, so that makes me believe that the Activator cant find the type, so im not to sure what to do from here.