Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Finding a GameObject from inside a ScriptableObject

Discussion in 'Scripting' started by Brian-Brookwell, Nov 1, 2017.

  1. Brian-Brookwell

    Brian-Brookwell

    Joined:
    Sep 14, 2012
    Posts:
    47
    I've a ScriptableObject that is attached to a GameObject. Is there any way to find the gameObject from the ScriptableObject?
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    6,700
    A ScriptableObject is an asset, it isn't attached to anything. You can reference a ScriptableObject from a MonoBehavior, and then put that MonoBehavior onto a GameObject, but that doesn't mean the SO knows anything about this relationship unless you build logic into it to know.

    What are you trying to use SO's for?
     
  3. Brian-Brookwell

    Brian-Brookwell

    Joined:
    Sep 14, 2012
    Posts:
    47
    A Sensory system. Since each sensor is basically data for it's shape and an origin, it made sense to put that into a ScriptableObject. That way it was only active when called.
     
  4. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    2,206
    Register the GameObject with the ScriptableObject when you instantiate it.
     
  5. Brian-Brookwell

    Brian-Brookwell

    Joined:
    Sep 14, 2012
    Posts:
    47
    That's what I thought I'd have to do. Thanks
     
unityunity