I am working on a Battle arena game, and i am following a tutorial i found on Youtube in regards to creating an ability factory (i’ll leave link below in case)
In the tutorials there an AbilityFactory script, which gets called into every time an ability is used.
and it look like this
public static Ability GetAbility(string abilityType)
{
if (abilititiesByName.CointainsKey(abilityType))
{
Type type = abilitiesByName[abilityType];
var ability = Activator.CreateInstance(type) as Ability;
return ability;
}
return null;
}
the GetAbility function use Activator.CreateInstance, which as far as i am concerned will create a new instance of the scripts every time an ability it used, is this the case? and if so, is there any problems associated with this way of using abilities. especially in regard to performance, if a lot of abilities is being used during a game.
And is there any better alternative to this, if this way causes problems?
link to video: Creating Objects in Unity3D using the Factory Pattern - YouTube