Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Feature request: SplineController.Position as inspector property
#1
I'd like to be able to easily control the Position value of a SplineController from a Timeline Animation Clip, but since Position is not exposed in the Inspector, there is no easy way to use the AddKey menu function from Timeline. It would be nice to do this without needing to create a custom C# script or modify the Curvy source code.

Thanks for considering. Smile
Reply
#2
I will try to make this work in the coming week. I will let you know here about the result of my attempt.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
(01-17-2018, 11:11 PM)_Aka_ Wrote: I will try to make this work in the coming week. I will let you know here about the result of my attempt.

Thanks. Let me know if you need a beta tester.

I have this working with an external script that simply exposes the needed parameter as a simple public float, initializes the float from the SplineController's own Position value at Start() time, then copies its own value to the SplineController's Position during Update(), LateUpdate(), or FixedUpdate() depending on which mode is selected.

For what it's worth, and in case it's helpful to anyone else, here's my working script, tested in Unity 2017.3.0f3 with Timeline.

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FluffyUnderware.Curvy.Controllers;

/*
* Exposes the Position value of a Curvy SplineController as a write-only property
* in the Unity inspector, to allow it to be animated with Timeline.
* This implementation assumes Relative position and move mode becasue that allows
* the inspector to set a range and provide a slider for the value, which is
* useful in visualizing the animation while editing Timeline. Experimentation
* also suggests Relative mode is better for Timeline animations because you
* don't have to later update the Timeline curves or keyframe values if the
* Curvy spline's length is changed.
*
* This is proof-of-concept code, not intended for production use.
*
* Author: Scott Courtney ("Syscrusher")
* License: MIT License
*/

[RequireComponent(typeof(SplineController))]
public class CurvySplineControllerPosition : MonoBehaviour {

SplineController curvy;

[Range(0.0f, 1.0f)]
public float RelativePosition;

// Initialize and set the prerequisites on the SplineController.
void Start () {
curvy = GetComponent<SplineController>();
curvy.PositionMode = FluffyUnderware.Curvy.CurvyPositionMode.Relative;
curvy.MoveMode = FluffyUnderware.Curvy.CurvyController.MoveModeEnum.Relative;
RelativePosition = curvy.Position;
curvy.Play();
}

// Push our position setting to the SplineController object
void PushPosition() {
if (isActiveAndEnabled) {
curvy.Position = RelativePosition;
}
}

// Update is called once per frame
void Update () {
if (curvy.UpdateIn == FluffyUnderware.Curvy.CurvyUpdateMethod.Update) {
PushPosition();
}
}

void FixedUpdate() {
if (curvy.UpdateIn == FluffyUnderware.Curvy.CurvyUpdateMethod.FixedUpdate) {
PushPosition();
}
}

void LateUpdate() {
if (curvy.UpdateIn == FluffyUnderware.Curvy.CurvyUpdateMethod.LateUpdate) {
PushPosition();
}
}
}
Reply
#4
The fundamental issue with making Position visible in the inspector (and consequently in the animation window) is that Position is a property, not a serialized field, and Unity does not display properties in the inspector.

Making Position a serialized field would need structural changes in the SplineController class (and other similar classes) to keep thinks clear and coherent from an API point of view, and from an UI based workflow point of view. Just to give you a glimpse of the issues, if Position is made a serialized field, then RelativePosition and AbsolutePosition need to become serialized fields too. Which means the code now needs to synchronize the values of all these fields (plus the mTF field currently used) to keep everything coherent. This is not impossible to do of course, but the ratio benefice/time_needed is too low compared to other tasks in the backlog.

Last night, while thinking about this, I was planning to end this post with a workaround for you and other people in your situation, but what you posted is already a very good workaround, so no need for me to add to it anything. Thanks for having shared this with the other Curvy users.

Sorry for my disappointing answer, but please keep in mind that other features/fixes/optimizations will be done instead.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
(01-18-2018, 01:42 PM)_Aka_ Wrote: Sorry for my disappointing answer, but please keep in mind that other features/fixes/optimizations will be done instead.

No apology needed. I asked for a new feature. You investigated and found that it's not technically feasible. You responded to my request with a rational explanation of your findings. I have a workaround that meets my requirements. All is well. Smile

Thanks for looking into this.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get position of all control points for a spline gekido 1 2 3 hours ago
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  Avoiding runtime GC allocations on control point position change Ell223 8 18 02-24-2024, 10:43 AM
Last Post: _Aka_
  How could I get position in spline from "From" value in BuildRasterizedPath? Chanon 1 8 02-12-2024, 09:54 PM
Last Post: _Aka_

Forum Jump: