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

How to get a reference to a compute shader from a System

Discussion in 'Entity Component System' started by HeliosJack, Mar 20, 2021.

  1. HeliosJack

    HeliosJack

    Joined:
    Aug 15, 2013
    Posts:
    41
    Typically in game object land, I would expose a ComputeShader property and drag the file into the slot in the editor in order to give a programmatic reference to the compute shader I write, right?

    Well in System land:


    Code (CSharp):
    1. public class MySystem : SystemBase
    2. {
    3.     public ComputeShader shader = default;
    4.  
    5.     ....
    6. }
    7.  
    isnt really going to get me anywhere. whats the alternative here?
     
  2. Mortuus17

    Mortuus17

    Joined:
    Jan 6, 2020
    Posts:
    105
    A simple alternative is just having a MonoBehaviour that sits in your scene and simply holds the references you need.
    You could either just reference them in your System through an instance of that MonoBehaviour, or destory the instance on OnCreate() after assigning the references to fields of the System.

    I would be interesed in better solutions, though, but this does work and I use it with GameObject only types like Cameras.
     
    HeliosJack likes this.
  3. HeliosJack

    HeliosJack

    Joined:
    Aug 15, 2013
    Posts:
    41
    Oh, I see. Thats a good practical solution to keep in mind for now. Thanks for responding with that tip! I was investigating other more painful and less likely to succeed solutions with Resources.Load