Skip to content

Create your own springs (extend the asset)

When no shipped component drives the thing you want, write one. SpringComponent handles initialization, the update loop, fixed time stepping, the debugger and the validity checks, and leaves you four small methods to fill in.

The asset ships a working template at Scripts/SpringsComponents/NewSpringComponentExample.cs. It is heavily commented and it compiles, so copying it is a reasonable way to start.

using UnityEngine;
using AllIn1Assets.AllIn1SpringsToolkit;
public class MyFovSpring : SpringComponent
{
public SpringFloat springFloat = new SpringFloat();
[SerializeField] private Camera targetCamera;
[SerializeField] private float targetFov = 60f;
// 1. Tell the toolkit which springs to run.
protected override void RegisterSprings()
{
RegisterSpring(springFloat);
}
// 2. Say whether this component has what it needs.
public override bool IsValidSpringComponent()
{
if (targetCamera == null)
{
AddErrorReason($"{gameObject.name} has no camera assigned.");
return false;
}
return true;
}
// 3. Seed the springs from something real, or they start at zero.
protected override void SetCurrentValueByDefault()
{
springFloat.SetCurrentValue(targetCamera.fieldOfView);
}
protected override void SetTargetByDefault()
{
springFloat.SetTarget(targetCamera.fieldOfView);
}
// 4. Use the value.
private void Update()
{
if (!initialized) { return; }
springFloat.SetTarget(targetFov);
targetCamera.fieldOfView = springFloat.GetCurrentValue();
}
}

RegisterSprings is not optional bookkeeping. A spring that is not registered never gets integrated, so it will sit there doing nothing and look like a broken spring rather than an unregistered one. Call RegisterSpring once per spring.

IsValidSpringComponent runs at startup and again every frame. Returning false disables the component and logs an error naming the object, and anything you pass to AddErrorReason is included. Re-checking every frame means a component whose reference gets destroyed mid-game switches itself off instead of throwing.

SetCurrentValueByDefault and SetTargetByDefault run during initialization. Seeding both from the live value is the usual choice, because it means the spring starts at rest and the object does not jump on the first frame. If you want the values to come from the Inspector instead, the base class exposes hasCustomInitialValues and hasCustomTarget to branch on, which is how the shipped components handle it.

The update can go wherever suits you. Update is fine, so is LateUpdate or a method you call yourself. The initialized guard matters if the component might be added at runtime, since adding a component in code means initialization happens when you say so.

Whatever matches your value: SpringFloat, SpringVector2, SpringVector3, SpringVector4, SpringColor or SpringRotation. They are covered on Spring Types, and inside your own component you get their full surface with nothing hidden behind an API layer.

Your component shows up in the Spring Debugger like any other, and it can use the custom icon buttons in the Asset Window.