- Home /
Alternative to using prefabs w/scripts to save sets of data for use at runtime?
I really like building instances of classes using the Inspector through a prefab. The benefits are numerous, and the code behind instantiation is clean. However, the only way (that I know of) to create an instance of the class is by creating a new GameObject when the class inherits from MonoBehaviour. Is there another way I can save instances of modified scripts edited through the inspector without inheriting from MonoBehaviour? Or, is there an easier way to create a copy of the referenced class as a new object while MonoBehaviour is inherited without creating a GameObject? I know that Unity doesn't like it when you declare a new Class():MonoBehavior, so creating a deep copy would also be another near impossibility.
public class AbilityMovement : MonoBehaviour
{
public string Name;
internal Quaternion FacingDirection;
public AnimationCurve DirectionX;
public AnimationCurve DirectionY;
public AnimationCurve DirectionZ;
internal Vector3 DirectionalMovement;
public float Force;
internal float VerticalSpeed;
public float Lifetime;
internal float RemainingLifetime;
public class AbilityInstance
{
public AbilityMovement Ability;
public AbilityInstance(AbilityMovement ability, Quaternion facingVectorDirection)
{
Ability = Instantiate<AbilityMovement>(ability);
}
}
}
Answer by mafima · Feb 09, 2018 at 12:55 AM
ScriptableObjects. they are like containers for exactly that.
scripts become modular
save them
load them
read them easily
no more hard referencing variables in your scripts
If your interested seeing whats possible with them, here is a online game i made: https://mut.itch.io/legends-of-mlg password is lol.
Your answer
Follow this Question
Related Questions
Creating a pointer variable to a GameObject inside a class that does not extend MonoBehavior? [C#] 2 Answers
GameObject reference breaks 1 Answer
Creating a reference gameobject of a prefab 0 Answers
Can I call a class's method which inherit monobehaviour by a normal class? 0 Answers
How to SetActive(false/true) on an instantiated object, being a clone? 1 Answer