Search Unity

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:
    7,529
    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:
    3,201
    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