Why would a widget not be grabbable?
hmmmm, any tips on why a widget I've made isn't grab- and movable? 🤔
31 Replies
What class is it?
Deriving from grabwidget iirc
Just on a walk right now
yup

I'd have to see the prefab hierarchy. Try copying a working prefab and swapping in your script subclass (use the debug mode trick to swap the scripts)
uhhh, I built it from scratch 🤔
currently it's just floating in the main scene, putting it into the panel manager just made it die xD
In general I always copy something that already works and modify it
Unless you know every single little component and setting that's required it's much safer
what widget prefabs are there to copy? 🤔
was also not really mentioned on the developer notes page, just stuff about guides 🤔
I hadn't done much with widgets when I wrote that but it's a similar approach to panels: use what works
this method in GrabWidget could have some things simplified to vector operations I think - but more importantly, it's ignoring the the collider.center offset in its calculations, so it may not work as expected in all cases

also the grabDistance part at the bottom ignores the local scale of the object, so the visual can mismatch the grab range
okay, I take back the part about vector operations, unity sucks 😩
@andybak
I hate that unity doesn't have Abs for vectors... or division... or...
It's got division: https://docs.unity3d.com/ScriptReference/Vector3-operator_divide.html
unless you mean component-wise division?
Can you give me steps to reproduce the bug that this fixes?
the bug(s) would be widgets using an offset in their boxcollider and scaled widgets using grab distance
I haven't tested this yet, but it's also easier to follow (imo)
hmmmmm, getting a funny spam now whenever I grab something (which breaks input) :'D

okay, that also happens without my change
okaaaay... with my custom widget disabled in the scene, this stops
dafuq
Pretty sure you've just forgotten to assign something in the prefab. Did you compare your hierarchy to a working widget?
well, these errors are happening because somehow prevGrabWidget is set to null in those methods, which is... weird
okay, I found the underlying problem, I think xD
it's just a single exception that gets flushed away by all the spam
idk what this NonScaleStuff is about, but Coords.AsGlobal[scaleParent] fails when the widget's transform is on the root of the scene

since scaleParent is null then
You've got a widget that's not a child of a CanvasScript?
yea, because it's not something the user creates 🤔
it's just a thing that gets spawned to show the user something
So more like a panel then? They are children of SketchControls
well... it's a ball that the user is supposed to be able to move too
Like a panel
Either it's a grabbable UI element or it's a grabbable scene element.
well, you told me it should be a grab widget 😅
buuut, with that null exception there fixed, it works now xD
It should be a grab widget. It just shouldn't be at the root of the hierarchy!
>:D
You might be ok but on the other hand there might be other unexpected side effects of doing that. If you want to play it safe then put it where other things live.
(also - note that panels themselves are subclassing GrabWidget)
mmm, as a secondary thing I guess
like where, when it's around from the start?
Not sure I follow. I'm just suggesting you stick to "Scene widgets are always childen of a canvas. UI widgets are always children of SketchControls". And assign the right Unity layer as well as that interacts with the spectator cam and other things.
yea, it is on the right layer