Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Multiple assets in one ScriptableObject-asset (in Project View)

Discussion in 'Scripting' started by IedSoftworks, Feb 21, 2022.

  1. IedSoftworks

    IedSoftworks

    Joined:
    May 27, 2021
    Posts:
    12
    Hello fellow coders,
    I currently trying to develop my weapon system and for the project view it would be nice, if I could f.E. have my weapon-scriptable object and the prefab for the weapon visually connected, similar how the import of meshes show all imported meshes, animations and materials.

    Is there a way how to do that with ScriptableObjects?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    You can make a reference from your ScriptableObject to your prefab.

    Beware that loading the ScriptableObject WILL also load the prefab.

    Beyond that you can also make custom editor inspector windows for your weapons.
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,008
    You can make your own sub assets of assets with the following editor scripts:
    https://docs.unity3d.com/ScriptReference/AssetDatabase.AddObjectToAsset.html
    https://docs.unity3d.com/ScriptReference/AssetDatabase.RemoveObjectFromAsset.html

    DO NOTE this is a pretty half baked feature from Unity. You are 100% responsible for keeping references to the sub assets in your SO or other Object as there is presently no way to easily find sub assets if you don't have a reference to them.

    Definitely play around with it in a test project to see if it works for you before you start using this in your project proper.
     
    fnnbrr, IedSoftworks, eses and 2 others like this.
  4. IedSoftworks

    IedSoftworks

    Joined:
    May 27, 2021
    Posts:
    12
    That was excatly what I was looking for. Thank you.
    I will test it in my test project.
     
  5. IedSoftworks

    IedSoftworks

    Joined:
    May 27, 2021
    Posts:
    12
    It worked lovely.
    Sadly prefabs don't work with that. At least, when I tried it, it said, that I had to use "PrefabUtiltys" and in there I haven't found any method that is similar to "AddObjectToAsset".

    (yes the gun the prefab is using the material. Something did went wrong with the rendering of the project view, but when I open it its the material.
    And yes the shader for the material is the particle shader, because its the only Unlit-shader with HDR in LRP)
    upload_2022-2-22_20-37-13.png