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 show variables depending on other variables in a Scriptable Object

Discussion in 'Scripting' started by GreenPhotonRays, Jan 28, 2023.

  1. GreenPhotonRays

    GreenPhotonRays

    Joined:
    Feb 25, 2022
    Posts:
    11
    Hey,
    I am currently working on a small game and i have this scriptable Object to store the information for my in-Game Obstacles/Objects. I use a boolean to determine whether the Object is breakable or not and if not there is no need for most of the other variables. Is it possible to do something like that? And if yes, how? I heard about custom editors and stuff, but I haven't heard enough about that to know if it could work or not. I hope you can help me.

    Ive got this code from my scriptable object I want to apply this on:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [CreateAssetMenu(menuName = "Objects/NewObjectInfo")]
    6. public class objectInfo : ScriptableObject
    7. {
    8.     [SerializeField] public bool breakable;
    9.     [Tooltip("When there is a parent objetct that connects multiple children that make logic sense together")]
    10.     [SerializeField] public bool hasConnectedObjects;
    11.  
    12.     [Space]
    13.  
    14.     [SerializeField] public float maxHealth;
    15.     [SerializeField] public string name;
    16.  
    17.     [Space]
    18.  
    19.     [Header("Loot info")]
    20.     [SerializeField] public int maxDropAmount;
    21.     [SerializeField] public int minDropAmount;
    22.     [SerializeField] public GameObject[] lootBox;
    23.  
    24.     [Space]
    25.  
    26.     [Header("Damage info")]
    27.     [SerializeField] public GameObject hitParticle;
    28.     [SerializeField] public GameObject breakParticle;
    29. }
     
    FlyMilk1 likes this.
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,606
    Yes custom editors are the way to go, which is the long and short of it really. You'll need to spend some learning how to make them, and there's no shortage of tutorials on how to do so. The docs even have basic starting examples: https://docs.unity3d.com/Manual/editor-CustomEditors.html
     
  3. GreenPhotonRays

    GreenPhotonRays

    Joined:
    Feb 25, 2022
    Posts:
    11
    Thank you for your reply!
    I guess I'll have to read a bit about that now, but now I know that it is possible, so it doesn't matter :)