Copy and paste curves?

Hi, I have a racing game I am working on, I have setup an acceleration curve to control a non player car and would like to apply that curve to my other cars.

Is there a way to copy and paste a curve? as it is mind numbing trying to do it manually.

Thanks!

I’ll take that as a ā€˜no’ then.

Try this :wink:

using UnityEngine;
using UnityEditor;

[CustomPropertyDrawer(typeof(AnimationCurve))]
public class CurvePropertyDrawer: PropertyDrawer {
	
	private const int _buttonWidth = 12;
	
	private static Keyframe[] _buffer;
	private static WrapMode _preWrapMode;
	private static WrapMode _postWrapMode;
	
	public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) {
		prop.animationCurveValue = EditorGUI.CurveField(
			new Rect(pos.x, pos.y, pos.width - _buttonWidth * 2, pos.height),
			label,
			prop.animationCurveValue
		);
		// Copy
		if (
			GUI.Button(
				new Rect(pos.x + pos.width - _buttonWidth * 2, pos.y, _buttonWidth, pos.height),
				""
			)
		) {
			_buffer = prop.animationCurveValue.keys;
			_preWrapMode = prop.animationCurveValue.preWrapMode;
			_postWrapMode = prop.animationCurveValue.postWrapMode;
		}
		GUI.Label(
			new Rect(pos.x + pos.width - _buttonWidth * 2, pos.y, _buttonWidth, pos.height),
			"C"
		);
		// Paste
		if (_buffer == null) return;
		if (
			GUI.Button(
				new Rect(pos.x + pos.width - _buttonWidth, pos.y, _buttonWidth, pos.height),
				""
			)
		) {
			AnimationCurve newAnimationCurve = new AnimationCurve(_buffer);
			newAnimationCurve.preWrapMode = _preWrapMode;
			newAnimationCurve.postWrapMode = _postWrapMode;
			prop.animationCurveValue = newAnimationCurve;
		}
		GUI.Label(
			new Rect(pos.x + pos.width - _buttonWidth, pos.y, _buttonWidth, pos.height),
			"P"
		);
	} // OnGUI()
	
} // class CurvePropertyDrawer

Put this script in Editor folder.

26 Likes

Hey there, just tried out that script; works like a charm! I think this should be a standard feature. I can’t thank you enough for saving me soooo much time. I’m using Animation Curves to control object velocity for special maneuvers. Time to make some magic :smile:

Thank you!! That’s a very neat piece of code there!

Cheers

Hello,

I put this script in Editor folder but I can’t see any copy/paste functionality in Animation window. Could you please explain me how to use it?

Thanks in advance,
Alejandro.

It’s for AnimationCurve property.
Not Animation window!

Thank you!

I’ve added this code to the Editor folder but I don’t know how to use it or what to do.
Any help will be appreciated.
Thanks in advance.

Hi - this seems awesome for animationCurves defined in your own scripts - but doesn’t work for animationCurves that you’ve added to animations… (in the Curve section…) any c

I also think this could be incredibly useful, but am unclear on how to install/use it. :frowning:

Haven’t logged in in a long time, Thanks!

define a variable of type AnimationCurve, and in the ā€˜inspector’ property panel, you’ll see it,

Thanks a lot for that script :)))

Is it possible to do the same thing for the Particle system curves?

For those just add it as a preset. Then select it when want to ā€œpasteā€ it.

1 Like


GitHubåœ°å€ļ¼šGitHub - akof1314/UnityAnimationCurvePopupMenu: Unity AnimationCurvePopupMenu (Copy, Paste)

2 Likes

Awesome!!!
For those not knowing how to use:

  1. Create Editor folder in your project (I did it within my Scripts folder, ending with Scrips\Editor)
  2. Create C# script, I named it CurveCopier (Obviously, move this script into the editor folder if it is not there yet)
  3. Edit this script, kill all its contents and place the above script within it.
    4.SAVE
  4. Now look next to your curve property on the script where you defined your curve… a small ā€œCā€ button appeared
  5. Click that button and a ā€œPā€ button will appear
  6. Now go to your target script with the curve you want to paste to, click the ā€œPā€ and Voila!!!
    (In my case, the curve picture suddenly matched my source curve, proving it worked.

Thanks again, I was just about to start typing values manually.

2 Likes

Awesome… thanks!

I know this is really old, but thank you

1 Like