Interactable Component only applies to host GameObject
I'm using a prefab object, composed of sub-objects that I can individually manipulate.
At some point, I would like to make the whole prefab interactable, in order to select it. So I figured I could use an interactable component that I could enable/disable at the root of the prefab instance.
Problem is, it expects everything to be set up at its host gameobject and does not seem to care about its children.
What would be nice is if the interactable component could be applied to the whole hierarchy of objects.
@killerantz I'm not sure if Interactable is designed for this use case, perhaps we need to clarify the documentation?
Let me try restate the goal. There's a prefab with Interactables as children, sub-objects that can be individually manipulated.
The desire is to:
- Add Interactable to the parent and have the other Interactables listen for state changes from the parent as well as their own interaction state changes?
- Add Interactable to the parent and turn on and off (enable/disable) children Interactables by turning on or off (enable/disable) the parent Interactable?
- Add Interactable to the parent and have sub objects respond to state changes without connecting them to a profile.
Some issues to solve:
- How to tell when to listen to the parent Interactable and when to listen to the sub-object Interactable.
- Some of the feedback you could put on a child object is to disable it, but once it's disabled, Update does not run on it anymore, so it won't pickup when it's time to enable itself again. This is one reason for the top down approach, that and the organization. I thought about building a profile that can sit on another object (child or sibling) and point to an Interactable to monitor in some use cases, this could still be done.
- Making sure the children can still be interacted with. The parent Interactable uses a collider to detect a pointer. If the children Interactables are inside the parent's collider, a pointer will never reach them.
Some ideas:
-
This one is pretty complicated. -- Maybe adding some additional states to the sub-objects (Like Default, Custom, Focus, Press, Disabled). Setup the sub-Interactable to use the new state object at the top of the Interactable. Then use some events on the parent Interactable to set states on the children, like on Parent focus, use the OnFocusReceiver event to set the children's Custom state to true, then add some feedback for that state on the children. When the parent gets focus, all the children could change colors for instance, but their own interaction would still override the parent.
-
You can definitely use events to set state or properties on other Interactables. This can be wired up in the editor manually, by assigning the values for each item, or a script to automate this. There's not an OnDisableReceiver written yet, but that's not too difficult, or just write a script to listen for a state change or to listen for the Interactable turning off. -- When the parent object is selected (toggled on) all the sub-objects could become enabled. Use the OnToggleReceiver on the parent's event section. Click Add Event, the use the drop-down to pick a receiver.
-
This can get messy, anytime there's a change finding all the children and update their values. Unless, we build a profile that can sit on them and look up the hierarchy to find an Interactable, this way themes would help with the mess. -- We something similar with the ReceiverBaseMonoBehavior, there's an example in the InteractablesExamples scene. The objects are called ReceiverExample and ReceiverExample (1), they listen to sibling Interacatbles for state changes and fire's events. This could be placed on a child Interactable with the Search Scope set to Parent, then it will automatically look up the hierarchy for an Interactable. Click the Add Event button to add events for OnFocus Press or toggled. This could be on an Instantiated Prefab too, because it will search for the Interactable on its own. Use this to help solve use case 1 or 2.
Let me know if these stated goals are close to what you're looking for.
Hello Todd.
Thanks for looking into this. To clarify, I do not have interactables on my sub objects, I have manipulation handlers.
My scenario is to spawn various objects (vectors) with sub parts that I can independently manipulate (base of the vector, to position its orign, tip of the vector for its direction). For convenience, I built them as a prefab that I can spawn at will, the object being managed with a component the root of the prefab. The root of the prefab does not have any other components (no colliders, no renderer)
Then, once I have a few of them, I would like to change the interaction mode to be able to select some of them to do something (TBD).
Easier thing I can imagine is to disable the manipulation handlers on my sub-objects, and enable an Interactable at the root. But as things stand :
- An interactable on each sub-object would not “highlight” the whole object.
- An interactable at the root does nothing.
I though about hijacking the manipulation notifications from the manipulation handlers to emulate selection, but that seems too complicated.
My desire is to have an Interactable consider the object with its children as a whole. I would say the proposition 3 is the closest?
I can definitely browse the hierarchy and disable the individual components that should not be active in a given interaction mode, so Issue 1 is not too bad. Issue 2 might not be relevant for me since the prefab root would manages this enable/disable logic. For Issue 3, well, I do not want to add a collider to the root. In a perfect world, the children colliders would be used.
I will try your ideas eventually, I would have to read more to make sense out of them, although my suggestion is to avoid doing all that, and have the top-most component apply its behaviour as if the whole hierarchy is a single object.
There's code that only sends the Interactable a message (events) if the Interactable is in focus, because a pointer hats it's collider. The events do not bubble up from sub colliders looking for event or message handlers. Making the Interactable global, will consume all the events though, this I think is super close to what you may want. The Interactable on the parent, with IsGlobal set to true will update states when child elements are interacted with, but it does consume the events so the children with Manipulation Handlers do not move, rotate or scale. It will also react to any interaction in the scene, not just child elements.
Seems like a script that registers as a global listener, looks for child elements with Manipulation handlers, and handle pointer events when one of the child elements are in focus. Then route the states to the Interactable.
The events do not bubble up from sub colliders looking for event or message handlers.
@killerantz actually, pointer and input events WILL bubble up from child colliders until something handles them...I'm a little confused by this statement.
marking as GA blocker because this bug impacts usability of Interactable in the "easy to customize" category.
@killerantz actually, pointer and input events WILL bubble up from child colliders until something handles them...I'm a little confused by this statement.
You are correct, apologies for the confusion. Looking forward to #4673!
Fixed by #4673