Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to 'start' or 'play' a curve asset in C++

Hello all! I was wondering how it would be possible to start a curve asset in C++. Thanks!

Product Version: UE 4.10
more ▼

asked Mar 16 '16 at 03:40 AM in C++ Programming

avatar image

91 18 19 28

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

Zip attached with code - you'd need to replace the Errorf with a standard UE_LOG and change headers to use in your project.

Here's a little wrapper:

 namespace Curves
     bool GetCurvePositionAtTime(const FString &rCurveName, float fTime, FVector &rOut)
         auto *pCurve = AMM_Curve::FindCurve(rCurveName);
         if (pCurve == nullptr)
             return false;
         rOut = pCurve->GetCurveValueAtTime(fTime);
         return true;

[Edit] Will attach blueprint image in a second, just upgraded to the latest preview and building new shaders.... [Edit2] Here's the blueprint - You could set this up in a simpler fashion, in my case I wanted to allow blueprints to be able to choose different curves for the C++ to use based on their author's logic. I would assume you could place a spline directly in an actor as a UPROPERTY.

alt text

link text

more ▼

answered Mar 16 '16 at 06:08 PM

avatar image

1.3k 61 68 271

avatar image Designer102 Mar 16 '16 at 11:34 PM

I was wondering more how to make it lerp like a timeline does in bleuprints, not just get a certain time.

avatar image Designer102 Mar 16 '16 at 11:35 PM

And I am not using blueprints.

avatar image theonecalledtom Mar 17 '16 at 01:07 AM

Then perhaps look into using UCurveVector or UCurveFloat. You'll still need to write a little class to do the interpolation but that's really simple - you just need to increment a float by deltaTime in some Tick function and use that to get the value at offset in the curve.

Or even implement your own Hermitic / Bezier / Catmull-Rom (first and last being generally my favorites) spline in C++ :) The curve interfaces I've seen in Unreal are pretty robust, allow for some cool editing etc but if you're not using any of that functionality a simple curve interpolation system isn't very hard to put together.

avatar image Designer102 Mar 17 '16 at 07:17 PM

That is what I was talking about when I said 'curve asset' sorry about that, should have been clearer. You mentioned that you can make a float curve have a lerp of sorts, in regards to that, maybe you could answer this question: https://answers.unrealengine.com/questions/390226/how-to-use-a-curve-to-create-a-smooth-transition-c.html

avatar image theonecalledtom Mar 18 '16 at 01:11 AM

saw the other thread but wasn't entirely sure how it was different to this one.

Suggest you post some code and try and explain the bit you're missing.

avatar image Designer102 Mar 18 '16 at 02:22 AM

That is the thing, I am not sure where to start, I have the curve involved in the script, but I am not sure how to get it to lerp like a timeline.

avatar image Designer102 Mar 18 '16 at 02:27 AM

You said to get a Ucurvefloat to lerp, you need to increment a float by deltatime in a tick function and use that to get a value from the curve, could you post a screenshot of that? I think thats what I am looking for, but I dont know what code it requires. (I am new to coding in C++, coming to c++ from C#) *Like just the syntax of what it needs, not a full script.

avatar image theonecalledtom Mar 18 '16 at 04:32 AM

One last thought is you're trying to do this in C++ not Blueprint. Is that for a specific reason - such as learning C++ (in which case I'd think Unreal might be a tough environment to learn)? Blueprints and editor defined objects provide much of the power of unreal so I'm not sure why you'd restrict yourself to avoiding them.

avatar image theonecalledtom Mar 18 '16 at 04:39 AM

Well, the website lost my more involved response, so my "last thought" didn't follow the detail it was meant to. Which sucks.

You're going to need some sort of AActor with a Tick function. Look these up in the documentation.

For instance:

 class MM_04_API AMM_Butterfly : public AActor

In that you'll want a timer that can be incremented (there are also functions within the actor to ask how long its been alive).

 float m_fTimer = 0.0f;

in the Tick function you're going to want to increment that value

I'm not sure what sort of handle you have on your curve (post screen shots, code snippets for better help!) but you can put something like this in your actor:

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Attraction)
     UCurveVector *SomeCurve;

And in your Tick function you can also use your timer to get a value back from this:

 virtual void Tick(float DeltaSeconds) override
     m_fTimer += DeltaSeconds;

     if (SomeCurve)

There is a host of documentation of AActor's, Tick functions, Timers, etc.

avatar image Designer102 Mar 18 '16 at 02:52 PM

Thanks! Going to have a look at the documentation, and I am not sure what: UCLASS() class MM_04_API AMM_Butterfly : public AActor means? Could you link me to the doc? And for the DoSomethingCoolWithThis would it be possible to do a GetCurvePositionAtTime, like would that have the value gotten be lerped?

avatar image Designer102 Mar 18 '16 at 03:05 PM

And the reason I am using C++ is because Blueprints change a lot and are unstable, and it feels kind of cheap to use them, since it is not really programming, more like an interface.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Probably a better way to do this but I created a curve actor type with functions grabbing length, position or tangent at time.

These functions are tagged blueprintimplementableevent and implemented in blueprint.

In my case these actors register themselves in a c++ map in begin play (and remove themselves in endplay) allowing c++ to find an editor authored curve by name. This allows for curves streaming in/out with levels.

Clunky but works, didn't take too long to implement.

more ▼

answered Mar 16 '16 at 02:32 PM

avatar image

1.3k 61 68 271

avatar image Designer102 Mar 16 '16 at 04:53 PM

Could you post a screen shot?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I've been using blueprints since version 4.4ish. A couple of early engine updates needed some rework but overall they've been usable and stable. You can write some fairly complex things in them and overall the power of unreal comes from combining blueprints and the editor for data editing with c++ where needed for either behavior or performance.

The butterfly class is a custom class of mine that I snipped bits of to demonstrate. My prior lost example was more obviously named :(

Given the concepts you're wondering about my advice is to follow tutorials. There are basic tutorials for placing actors in the world, attaching blueprint behaviors and creating custom c++ classes to further develop behaviors. A few hours spent following these tutorials and exploring the example content provided in the engine will give you a more solid understanding of the engine to build on before you try implementing something of your own.

Topics to look at:

  • placing an actor

  • Adding a blueprint behavior to an actor

  • Adding a custom c++ actor class

  • Exposing c++ properties to the editor

  • Calling c++ functions from blueprint

  • Calling blueprint functions from c++

more ▼

answered Mar 18 '16 at 05:39 PM

avatar image

1.3k 61 68 271

avatar image Designer102 Mar 18 '16 at 07:40 PM

Its okay, I prefer not to use blueprints for various reasons.

avatar image Designer102 Mar 18 '16 at 07:44 PM

Thanks for all the responses! I have figured out what I am going to do, use a tick function similar to what you did, to lerp the curve value, Thanks.

avatar image theonecalledtom Mar 29 '16 at 09:58 PM

Hope something helped - you can accept one of my responses as an answer to close the subject and give me brownie points!

avatar image Designer102 Mar 30 '16 at 05:06 PM

Yeah, sorry about that.

avatar image Designer102 Apr 02 '16 at 04:45 PM

Thanks for the tips and stuff too, really helped.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question