Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving multiple controllers at once
#11
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. Sad
Reply
#12
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.
Reply
#13
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. Sad

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.
Reply
#14
(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. Sad

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.
Reply
#15
(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. Huh  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. Big Grin 

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.
Reply
#16
(02-02-2020, 06:49 PM)Lupp_ Wrote: Yes I know this, you answered with the exact same line as I posted as example. Huh 
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.
Reply
#17
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?  Huh
Reply
#18
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.
Reply
#19
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.
Reply
#20
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Distance travelled across multiple splines jh092 1 7 02-23-2024, 09:44 AM
Last Post: _Aka_
  Best practice for controllers slowing down/speeding up along the spline Curry 1 5 08-06-2023, 09:47 PM
Last Post: _Aka_
  Moving object down or up the spline using gravity velikizlivuk 6 16 07-26-2023, 10:06 PM
Last Post: _Aka_
  Multiple Splines and Generators Performantly for Road System drock 1 6 07-17-2023, 10:31 AM
Last Post: _Aka_

Forum Jump: