Create a curve based on a mathematical equation

Hi, I have not found the answer to this question searching the forum, so asking here:

  • How can I create a curve asset based on a mathematical equation instead of creating keypoints manually?

For instance, I’d like to use a curve for XP generation that is based on a logarithm. Or if not possible, something along the lines of y=x^2.

Any hint will be welcome

Unreal has math functions built in- though it isn’t exactly a curve, you can sample it just the same.

	int32 GetTotalExpCost(int32 Level)
	{
		// y=x^2
		//return FMath::Pow(Level, 2.0);

		// y = log_2(Level)
		//return FMath::Log2(static_cast<double>(Level + 1));

		// y = log_3(Level)
		//return FMath::LogX(3.0, Level + 1);
	}
	
	int32 GetNextLevelExpCost(int32 Level)
	{
		return GetTotalExpCost(Level) - GetTotalExpCost(Level - 1);
	}

The +1 is only necessary if you’re starting at level 0 and are using a logarithm.

I wrote this in cpp, but the exactly same can be done in blueprint via the exact same methods:

Thanks for the answer… this is not using a curve though, unless I am mistaken.

I understand that you can calculate the desired values if so you wanted to, but I was curious if it was possible to specifically create a curve asset based on an equation.

Maybe it’s not possible?

Yes- it’s not using a curve. I’m not sure why you’d need a curve for exp when you’re intending to use a flat equation.
If you absolutely need it to be a curve asset, your best bet will be to manually make a shape that resembles it.

I checked the curve source files, but couldn’t find an easy in. It’s all heavily tied into the editor- they aren’t meant to allow raw equations. The only way I can think of doing it would be jank and not at all worth it.

Thanks for your help