Search Unity

Resolved Storing child class objects in list of parent objects from editor? Scriptable Objects and Assets?

Discussion in 'Documentation' started by DTECTOR, Aug 10, 2022.

  1. DTECTOR

    DTECTOR

    Joined:
    Aug 23, 2020
    Posts:
    132
    I am trying to figure out how to handle a class that has some fields and a method. I don't want all the stuff that comes with MonoBehavior. This class will only ever be stored on an object and that object will call the single method on this class that has an overridden definition from an abstract class.

    I have numerous classes that inherit from the same abstract class to have the behavior of an interface but while also passing on all the fields and members that will be in every single class. The one unique implementation detail is the logic within the method.

    I am looking at storing this as scriptable object? But I am reading that it's only for data no methods? It also says in the docs that you have to store it as an ASSET in the editor. But when I look up what the heck an asset is I get nothing. It seems to be some magical thing that isn't explained. All I get is Asset Store information.

    What is an Asset in Unity? Is there some docs or something that explain this in depth? Can scriptable object have methods? And would this be the ideal solution?

    Example:

    public abstract class Ability
    {
    fields;
    properties => fields;

    AbstractMethodForUniqueDefinitionPerClass(Param param1);
    }

    public class AbilityOne : Ability
    {
    Over Method()
    {
    Definition;
    }
    }


    Each of these abilities? Would I store these as assets? Or scriptable object? From the documentation I don't get a clear sense of what to do or even what scriptable object is other than basically a visual template for a struct (although structs can have methods now).

    I found this for Asset:
    https://docs.unity3d.com/ScriptReference/VersionControl.Asset.html

    But it doesn't explain anything regarding an Asset or what it is or what you should use it for. I don't even think it's actually refering to an Asset but regarding version control info on an "Asset" that magical thing that doesn't seem to be defined anywhere? (That I have looked)

    My end goal is to be able to assign these abilities in the editor. But hopefully without monobehavior because I don't need transform as it's just data and a method, no location or any of that.
     
  2. DTECTOR

    DTECTOR

    Joined:
    Aug 23, 2020
    Posts:
    132
    I've edited the title to reflect where I think this is going. I realized even if I use monobehavior, I still can't add the abilities from editor because they are child classes and they need to be cast to parent type. That is pretty straightforward in code, but in the editor is that possible?

    My initial assumption is maybe you create this functionality in a custom editor or something?

    I'd still like to understand what Asset means in relation to what you are creating when you create a scriptable object in Unity. Does it store an instance of the class just in a file that you can move around? Because my issue is I have C# classes that I want to be able to be passed around and stored/serialized via editor without using MonoBehavior, and I worry scriptable object is not the one as I have seen people saying in forums not to use it with methods and the docs specifically say data that is referenced. I don't even need the functionality of the scriptable object with changing values or fields, just want to be able to have the objects in editor and click and drag them into a serializefield list of parent class objects.