Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to make a list that can contain different variable types?

Discussion in 'Editor & General Support' started by disappointedcreeper, May 29, 2023.

  1. disappointedcreeper

    disappointedcreeper

    Joined:
    Oct 23, 2021
    Posts:
    27
    I am making a cutscene handler, and I want to make it so there is a list that can accept any type of ScriptableObject that I specify, for example DialogueData, Movement, and Emote. I want to be able to set them in any slot, and take it up, but I am thinking of just making it so that it can have all 3, and just leave the others null, with something to check for which one is not null. (If it matters the game is 2D.)
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Do you know about Timeline? It's pretty handy for making cutscenes!

    https://docs.unity3d.com/Packages/com.unity.timeline@1.2/manual/index.html

    Otherwise, if you insist on reinventing your own Timeline, you could just make a
    ScriptableObject[] array
    and be done with it.

    Then using interfaces you can have a common way to get at each one you find.

    Using Interfaces in Unity3D:

    https://forum.unity.com/threads/how...rereceiver-error-message.920801/#post-6028457

    https://forum.unity.com/threads/manager-classes.965609/#post-6286820

    Check Youtube for other tutorials about interfaces and working in Unity3D. It's a pretty powerful combination.
     
  3. disappointedcreeper

    disappointedcreeper

    Joined:
    Oct 23, 2021
    Posts:
    27
    I'll look into that, but I don't know if it is right for me, because of how I plan on having cutscenes work in my game.
     
  4. disappointedcreeper

    disappointedcreeper

    Joined:
    Oct 23, 2021
    Posts:
    27
    The timeline looks like it could work, but I don't think it fits my workflow. I prefer having complete control over everything, and don't really like the way that kind of thing works.