Why would a widget not be grabbable?

hmmmm, any tips on why a widget I've made isn't grab- and movable? 🤔
31 Replies
andybak
andybak•2y ago
What class is it?
Banane9
Banane9OP•2y ago
Deriving from grabwidget iirc Just on a walk right now yup
Banane9
Banane9OP•2y ago
No description
andybak
andybak•2y ago
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)
Banane9
Banane9OP•2y ago
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
andybak
andybak•2y ago
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
Banane9
Banane9OP•2y ago
what widget prefabs are there to copy? 🤔 was also not really mentioned on the developer notes page, just stuff about guides 🤔
andybak
andybak•2y ago
I hadn't done much with widgets when I wrote that but it's a similar approach to panels: use what works
Banane9
Banane9OP•2y ago
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
No description
Banane9
Banane9OP•2y ago
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
virtual public float GetActivationScore(
Vector3 vControllerPos, InputManager.ControllerName name)
{
if (m_BoxCollider)
{
var bounds = m_BoxCollider.bounds;
var extents = bounds.extents;

var controllerOffset = vControllerPos - bounds.center;
var extentRatio = new Vector3(Mathf.Abs(controllerOffset.x) / extents.x, Mathf.Abs(controllerOffset.y) / extents.y, Mathf.Abs(controllerOffset.z) / extents.z);

if (extentRatio.x > 1 || extentRatio.y > 1 || extentRatio.z > 1)
return -1;

extentRatio *= .333f;
return 1 - extentRatio.x - extentRatio.y - extentRatio.z;
}

var controllerDistance = transform.InverseTransformPoint(vControllerPos).magnitude;

if (controllerDistance > m_GrabDistance)
return -1;

return 1 - (controllerDistance / m_GrabDistance);
}
virtual public float GetActivationScore(
Vector3 vControllerPos, InputManager.ControllerName name)
{
if (m_BoxCollider)
{
var bounds = m_BoxCollider.bounds;
var extents = bounds.extents;

var controllerOffset = vControllerPos - bounds.center;
var extentRatio = new Vector3(Mathf.Abs(controllerOffset.x) / extents.x, Mathf.Abs(controllerOffset.y) / extents.y, Mathf.Abs(controllerOffset.z) / extents.z);

if (extentRatio.x > 1 || extentRatio.y > 1 || extentRatio.z > 1)
return -1;

extentRatio *= .333f;
return 1 - extentRatio.x - extentRatio.y - extentRatio.z;
}

var controllerDistance = transform.InverseTransformPoint(vControllerPos).magnitude;

if (controllerDistance > m_GrabDistance)
return -1;

return 1 - (controllerDistance / m_GrabDistance);
}
I hate that unity doesn't have Abs for vectors... or division... or...
andybak
andybak•2y ago
unless you mean component-wise division? Can you give me steps to reproduce the bug that this fixes?
Banane9
Banane9OP•2y ago
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)
Banane9
Banane9OP•2y ago
hmmmmm, getting a funny spam now whenever I grab something (which breaks input) :'D
No description
Banane9
Banane9OP•2y ago
okay, that also happens without my change okaaaay... with my custom widget disabled in the scene, this stops dafuq
andybak
andybak•2y ago
Pretty sure you've just forgotten to assign something in the prefab. Did you compare your hierarchy to a working widget?
Banane9
Banane9OP•2y ago
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
Banane9
Banane9OP•2y ago
idk what this NonScaleStuff is about, but Coords.AsGlobal[scaleParent] fails when the widget's transform is on the root of the scene
No description
Banane9
Banane9OP•2y ago
since scaleParent is null then
andybak
andybak•2y ago
You've got a widget that's not a child of a CanvasScript?
Banane9
Banane9OP•2y ago
yea, because it's not something the user creates 🤔 it's just a thing that gets spawned to show the user something
andybak
andybak•2y ago
So more like a panel then? They are children of SketchControls
Banane9
Banane9OP•2y ago
well... it's a ball that the user is supposed to be able to move too
andybak
andybak•2y ago
Like a panel Either it's a grabbable UI element or it's a grabbable scene element.
Banane9
Banane9OP•2y ago
well, you told me it should be a grab widget 😅 buuut, with that null exception there fixed, it works now xD
andybak
andybak•2y ago
It should be a grab widget. It just shouldn't be at the root of the hierarchy!
Banane9
Banane9OP•2y ago
>:D
andybak
andybak•2y ago
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)
Banane9
Banane9OP•2y ago
mmm, as a secondary thing I guess like where, when it's around from the start?
andybak
andybak•2y ago
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.
Banane9
Banane9OP•2y ago
yea, it is on the right layer

Did you find this page helpful?