Posts: 64
Threads: 11
Joined: Dec 2019
I know this is not really a Curvy problem, but I have searched and searched and even asked on the Unity forums (which are horrible and you never get an answer, or a correct one) so I see no option but to ask here. I've probably already found the answer but the Unity manual is crap most of the time and does not give any suggestion how to actually use the functions.
What I want is to have a cancel function for the slider that offsets the controllers. For that I need to tell the editor to either cancel slider dragging even if the mouse is pressed, or a way to cancel the mouse press.
A simple thing I thought, but no, I can't find anything that works.
Posts: 1,954
Threads: 80
Joined: Jun 2017
Hi,
Yeah, unfortunatly Unity's documentation is far from being the best, but is not the worse neither. But still, it can improve greatly.
I am not aware of ways to cancel mouse interactions, sorry about that.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Posts: 64
Threads: 11
Joined: Dec 2019
So after getting side tracked for way too long trying to learn about ways to get around weird quirks in Unity, I'm finally at the point there I can interact with the controllers. Unfortunately I don't understand the syntax on how to do that.
What I want it to make is: - A foreach loop and store all the absolute positions of the controllers from this, and store it in a new array.
Code: var selectedControllers = Selection.transforms.Select(t => t.gameObject.GetComponent<SplineController>()).Where(c => c != null).ToList();
- How to set those objects to a new absolute position based on the new modified array.
- How to get the end point of the controllers splines as an absolute value.
Posts: 1,954
Threads: 80
Joined: Jun 2017
(02-02-2020, 04:57 PM)Lupp_ Wrote: So after getting side tracked for way too long trying to learn about ways to get around weird quirks in Unity, I'm finally at the point there I can interact with the controllers. Unfortunately I don't understand the syntax on how to do that.
What I want it to make is: - A foreach loop and store all the absolute positions of the controllers from this, and store it in a new array.
Code: var selectedControllers = Selection.transforms.Select(t => t.gameObject.GetComponent<SplineController>()).Where(c => c != null).ToList();
- How to set those objects to a new absolute position based on the new modified array.
- How to get the end point of the controllers splines as an absolute value.
Hi, - To set and get the absolute position, use the AbsolutePosition property.
- To store them in an array, you can use a simple foreach. If you want to use Linq (warning, this means a memory allocation at each call), you can do this: Selection.transforms.Select(t => t.gameObject.GetComponent<SplineController>()).Where(c => c != null).Select(c => c.AbsolutePosition).ToList()
- If I understood correctly you question about the end point, you need to use the CurvySpline.Length property
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Posts: 64
Threads: 11
Joined: Dec 2019
(02-02-2020, 05:43 PM)_Aka_ Wrote: Hi,- To set and get the absolute position, use the AbsolutePosition property.
- To store them in an array, you can use a simple foreach. If you want to use Linq (warning, this means a memory allocation at each call), you can do this: Selection.transforms.Select(t => t.gameObject.GetComponent<SplineController>()).Where(c => c != null).Select(c => c.AbsolutePosition).ToList()
- If I understood correctly you question about the end point, you need to use the CurvySpline.Length property
Yes I know this, you answered with the exact same line as I posted as example. What I need to know is what to actually type to get AbsolutePosition from the array you posted. I tried to look at some scripts that comes with the example scenes for some hints, but it's no good, I can't figure out how the syntax works. To make it clear, I know what to do, just not how.
What I meant by end point is the value of the final control point, that is the maximum value the controllers position can be/is clamped at.
Posts: 1,954
Threads: 80
Joined: Jun 2017
(02-02-2020, 06:49 PM)Lupp_ Wrote: Yes I know this, you answered with the exact same line as I posted as example. My line has a .Select(c => c.AbsolutePosition) at the end. The full line I gave you will return to you a list of floats, each entry being an Absolute Position
(02-02-2020, 06:49 PM)Lupp_ Wrote: What I need to know is what to actually type to get AbsolutePosition from the array you posted youcontroller.AbsolutePosition;
(02-02-2020, 06:49 PM)Lupp_ Wrote: What I meant by end point is the value of the final control point, that is the maximum value the controllers position can be/is clamped at. Relative position is clamps to 1, absolute position is clamped to spline.Length
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Posts: 64
Threads: 11
Joined: Dec 2019
Sorry but I must bother you one more time. This code gives no errors in Visual B.
Code: private void OnEnable()
{
List<SplineController> selectedItems = Selection.transforms.Select(t => t.gameObject.GetComponent<SplineController>()).Where(c => c != null).ToList();
if (selectedItems.Count > 1)
{
index = 0;
controllers = selectedItems.ToArray();
makeWindow = true;
foreach(SplineController checkController in controllers)
{
orgPos[index] = checkController.AbsolutePosition;
maxPos[index] = checkController.Spline.Length;
Debug.Log(orgPos[index]);
Debug.Log(maxPos[index]);
Debug.Log(controllers[index]);
index++;
}
}
But once in Unity I get this when I select objects with controllers.
Quote:NullReferenceException: Object reference not set to an instance of an object
FluffyUnderware.CurvyEditor.Controllers.MoveMultipleControllers.OnEnable () (at Assets/Game Assets/Editor/MoveMultipleControllers.cs:42)
Line 42 is the first in the loop.
I don't get this, doesn't "List<SplineController> selectedItems" contain the controllers or is it something else I've done wrong?
Posts: 1,954
Threads: 80
Joined: Jun 2017
I really can't help since I don't know which line is line 42. Anyways, to solve such problems, you need to use a debugger, and check you variable to find which one is null.
https://docs.unity3d.com/Manual/ManagedCodeDebugging.html
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Posts: 64
Threads: 11
Joined: Dec 2019
I've been checking variables and things and nothing seemed to be wrong. Then I saw this when I clicked on a controller.
https://imgur.com/utYXZxF
After some fiddling I found the reason, [CustomEditor(typeof(SplineController))]. Disabling that returned the inspector back to normal so it might be the reason for the error. I don't know yet cause now the script does not work so I have to redo a bunch of stuff to make it work without CustomEditor. But it's a start I guess.
Posts: 1,954
Threads: 80
Joined: Jun 2017
Hi,
While reading again your post, I noticed the "Line 42 is the first in the loop." that I missed when I first read it. So the line being
orgPos[index] = checkController.AbsolutePosition;
means that either orgPos is null, or checkController is null. Since checkController comes from selectedItems which does not contain null items, the reasonable conclusion would be that orgPos is null. The easy way to confirm this is to Log orgPos and checkController before using them line 42.
I feel that by going down the [CustomEditor(typeof(SplineController))] road, you are hunting the consequence and not the cause of your issue. Stay focused on the null reference. If there is a null referencing and you check and don't fin anything wrong, that means that you haven't checked good enough. With the logs I suggested earlier you will definitely find which variable is null
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
|