[Open Beta] Procedural On-the-Fly Animation in UE4: iTween!

Hello,

I’m using iTween to simulate a car traffic for a short presentation using Unreal Engine 4. I want to have the car tween through the entire spline but can pause/stop tweening at any time on the road when I tell it to.

The traffic simulation is shown as a 4-way intersection with traffic lights, with the camera situated above the ground, looking down from an overview angle. The spline for the car starts from the road at the bottom, and ends on the road to the left. I want to be able to halt the car in the middle of the intersection while it is running the tweening animation, and resume playing the tweened animation after a delay.

How can I tell it to pause its tweening animation, and resume playing the tweening animation? Thanks.

Yo Ity, welcome to iTween!

you have two options. Either way you’ll have to add the iTInterface to your car blueprint (Class Options > Interfaces > Add > iTInterface). This will not work in a Level Blueprint because they do not use interfaces.

Option 1:

Set up a MoveActorToSplinePoint tween on your car’s blueprint and plug in your spline. Name it something like “TweenCar.” Make sure “self” is plugged into “ActorToTween” and “OnTweenUpdateTarget.” With iTInterface implemented, find “EventOnTweenUpdate” and from that run a switch using the TweenName output and check for “TweenCar” or whatever you named it. If that’s the name of the Tween being evaluated on that frame, you can check to see its AlphaCompletion. This is a normalized value between 0 and 1 which shows how far along into the animation you currently are, 0 being “just started” and 1 being “finished.” Since you’re turning into an intersection and stopping, I’d guess the alpha completion you’re looking for is 0.5, but you can try different values to see what works. When you’ve reached that AlphaCompletion value, use PauseTweeningByTweenName then set a timer that calls ResumeTweeningByTweenName after your delay. Make sure you write the Tween Name in each of these nodes. The name is case-sensitive.

This will allow you to keep using your current setup, but may look a bit too robotic since the tween will not slow to a stop to pause. It will just stop. It won’t slow to resume either. If you want to ease in and out of these, you’ll have to have multiple tween which is option 2.

Option 2:

Set up two splines instead of 1. Spline1 begins at the bottom and ends in the middle of the intersection, Spline2 starts where Spline1 ended and ends itself to the left. Set up a MoveActorToSplinePoint tween on your car’s blueprint and plug in Spline1. Name it something like “TweenCarPart1.” Make sure “self” is plugged into “ActorToTween” and “OnTweenCompleteTarget.” With iTInterface implemented, find “EventOnTweenComplete” and from that run a switch using the TweenName output and check for “TweenCarPart1” or whatever you named it. If that’s the name of the Tween that just finished, you can then set a timer that waits for your delay and sets off another MoveActorToSplinePoint using Spline2. In this one, you’ll notice “MoveToPath” is turned on. This option makes your actor move to the beginning of the next spline to prevent it from popping into place if Spline2’s first vertex isn’t in the exact same spot as Spline1’s last vertex.

This means you’ll have to modify your scene some, but the work is minimal and you’ll be able to ease in and out of your “pause.”

Let me know how this works out for you. Good luck!

I’m encountering an issue whenever I try to package my C++ project (for any of the debug, development or shipping builds): it’s got the C++/Blueprints version of iTween, but every time I try to package the game, the log shows that iTween can’t be found. However, when I run the project from inside Unreal Editor, all of the iTween stuff works, and similarly, I can access the iTween nodes in Blueprints after building them in Visual Studio. This is the line in the log I get:


[2016.04.20-19.26.42:568]  0]LogUObjectGlobals:Warning: Failed to load '/Script/iTween': Can't find file for asset '/Script/iTween' while loading NULL.
[2016.04.20-19.26.42:568]  0]LogLinker:Warning: Can't find file '/Script/iTween'

Any assistance would be appreciated; thanks!

Hey Infinite Zenith!

Usually this sort of thing is caused by redirectors being moved outside of the project, usually by Windows Explorer or Finder. The strange thing is that it doesn’t really apply to C++ code, at least not usually.

When iTween for UE4 launched, it was Blueprint-based rather than code-based. Has your project ever used this version before? Deleting the assets after moving to the code-based version, especially deleting them from outside the editor, may cause this issue.

If so, it may be as easy as right-clicking your content folders inside the editor and choosing “Fix up redirectors.”

Sources:

There are many more results on Google when searching “Can’t find file for asset while loading NULL.”

If you have never used the asset version, then let’s try to troubleshoot :slight_smile:

-Which version of the editor are you currently using?
-Which version of iTween are you currently using?
-Can you run the game in Standalone mode?
-Which platform are you packaging for?
-Can you reproduce this in a new project copying over your source and content folders and rebuilding?

Thanks!

Hi

Thanks for getting back so quickly :slight_smile: The project I’m working on was a Blueprint-only project once, but then I migrated it to a C++ project later. Unfortunately, choosing “Fix up redirectors” didn’t seem to fix the error. I’ll continue digging, but 's a bit more about my project:

-I’m using Unreal 4.8.3
-I’m using iTween 0.8.6b
-The game runs fine in standalone mode
-I’m packaging for Windows x64
-If I build a new C++ project, install iTween via the installer and then try to package it, the packaging seems to work

Again, many thanks!

Truth be told there were some packaging issues I fixed in more recent versions. I don’t think the issue you’re having is related, but if you have time, try this:

-Download 4.11
-Download the latest iTween from the first page
-Create a new project in 4.11
-Copy over your source and content folders from your current project to the new project. You can copy config and saved over if you want, that shouldn’t affect anything. Of course, do not copy Intermediate.
-Delete the iTween folder from Source
-Add iTween to the new project (C++ version)
-Go into Build.cs for the new project and make sure “EditorStyle” is removed from your public dependency modules.
-Rebuild the project.

This is essentially a hard reboot for your project. Anything that’s still lingering in terms of redirectors should be cleared out and if the packaging issues are caused by iTween, updating to the latest version should fix them. The latest version is only compiled for 4.11, so that’s why you must update to the latest engine version as well.

I am so glad I found this nice plugin! It should be on the marketplace once it gets out of beta :wink:

One thing to note though is that I am having an issue with recognizing when the animation stops. Using the nodes in the level blueprint, so the Tinterface will not work. However, I think I have found at least a method to get it to work though. On the animation duration, I have that as a float variable. The tick is in seconds though.

When I tried the math, multiple / divide / add… everything I could think of, and then plug that value into the Start timeline (Finished), it plays, or rather, stops playing, the nodes that I want to stop playing. Any ideas? The values I can think of that would work are:

  • Timer float variable (30 in my case), set to tick: seconds
  • Spline length
  • New Timeline

Hey SaviorNT, thanks :slight_smile:

I’m not 100% sure what you’re asking though, can you add some screenshots of your current setup?

If I understand correctly, you want to have a timeline along with your tween and stop the tween when the timeline finishes? Or start a timeline when your tween finishes?

Well, the idea is to stop sounds when the tween finishes. I found that you could add an interface into the level blueprint, but using the When Tween Completes doesn’t work? Or I have it set up incorrectly.

You’re calling On Tween Complete. What you want to do is override the event. With your interface implemented and blueprint compiled, search for “EventOnTweenComplete.” It’s red. Level blueprints can indeed use interfaces as of 4.11 (maybe earlier) so you’re not very far from the right answer :slight_smile:

Hi

I’ve tried everything under the sun, and the project adamantly refuses to be updated to 4.11 (i.e. iTween still thinks it’s looking for the 4.8 files, and those ones look like they’re looking for the Blueprint-only files) when I try to copy the stuff over. The only option that’s remotely viable is to completely rebuild each Blueprint and scene from old project, from scratch, in 4.11. Nonetheless, thanks for the suggestions.

Hi ,
great plug-in, thank you very much for it.
I got a question though- I’ve created a spline BP in UE4, I have a camera and when using ITween I want not only for the camera to follow the spline but also to rotate according to the spline curves (if that makes any sense).
Currently I have the camera following the spline but the camera always faces in one direction only (forward) even at the curves of the spline.
I am using the Actor Move To Spline Point (Full) and changing the Orientation to “target” or “path” changes nothing- camera is still pointing forwards throughout its viewport animation. I tried using an Orientation target (I used one of the static objects in my scene) but that also didn’t change the camera orientation while moving.
Am I doing something wrong?

Any help would be much appreciated.
Thanks again for the great plugin.

Sorry again Zenith, I don’t know what else could be the issue. Perhaps, one more thing. Check to see if any of your old blueprints have the old iTInterface implemented. If there’s still a reference to it, it may be causing your blueprints to look for the old iTween set.

Hello branskyj, thanks for the compliments! Just remember it always helps to get a look at your setup when asking for help!

I just retested this myself and can’t reproduce the issue. As you can see in this gfycat the camera follows the spline’s contours as expected. The Orientation is set to “Path.”

Can you provide a screenshot of your setup? There might be something that’s getting overlooked.

Hi , many thanks for your response.
I am attaching a screenshot of my Level Blueprint where I have created the ITween. I do see mine is more simple than yours though, maybe I am missing some important bits… I am very new to UE4, apologies.
I tried to read your bluescript but the resolution of the GIF was too low, would it be possible for you to upload a screenshot of it?
Again- thank you very much for the help.

Looking at your BP, nothing seems different enough to suggest that the rotation wouldn’t work.

-Are you absolutely sure you don’t have any blueprints that affect the camera?
-Does the Camera have “Use Pawn Control Rotation” turned on?
-Can you plug another actor into the tween like a random static mesh? Does it rotate with the spline?
-Can this be reproduced in a clean new project with iTween added to it?

Hi ,
you are absolutely right. When I added a movable object to the iTween it worked as intended. So it must be something about the camera I am using…
By the way the “Use Pawn Control Rotation” on the camera was OFF, turning it ON didn’t make any difference.
Anyway- that is for me to figure out, the plug in works great and is fantastic.

Thank you very much again and have a nice weekend :slight_smile:

I hope you figure it out! I’d try throwing another camera in there just to test it. Maybe something references that camera and prevents rotation in some way.

This plugin is very good! I already use this plugin in my own project.

But I think it will more convenience if you add TFunction callback to this plugin, so we can receive callback for any class we implement.

I already implement this by myself:

UCLASS()
class AiTweenEvent : public AActor
{

public:
typedef TFunction<void(AiTweenEvent*, UObject*)> FOnTweenCallbackFunction;
void SetTweenStartCallback(const FOnTweenCallbackFunction& callback) {
OnTweenStartFunction = callback;
};
void SetTweenUpdateCallback(const FOnTweenCallbackFunction& callback) {
OnTweenUpdateFunction = callback;
};
void SetTweenLoopCallback(const FOnTweenCallbackFunction& callback) {
OnTweenLoopFunction = callback;
};
void SetTweenCompleteCallback(const FOnTweenCallbackFunction& callback) {
OnTweenCompleteFunction = callback;
};

};

void AiTweenEvent::RunCallbackInterface(UObject* target, FString type) {

if (target)
{
	if (type == "start")
	{
		if (OnTweenStartFunction.IsSet()) {
			OnTweenStartFunction.GetValue()(this, target);
		}
	}
	else if (type == "update")
	{
		if (OnTweenUpdateFunction.IsSet()) {
			OnTweenUpdateFunction.GetValue()(this, target);
		}
	}
	else if (type == "loop")
	{
		if (OnTweenLoopFunction.IsSet()) {
			OnTweenLoopFunction.GetValue()(this, target);
		}
	}
	else if (type == "complete")
	{
		if (OnTweenCompleteFunction.IsSet()) {
			OnTweenCompleteFunction.GetValue()(this, target);
		}
	}
	
}

}

And add following to each callback phase:

RunCallbackInterface(onTweenCompleteTarget, “complete”);
RunCallbackInterface(onTweenStartTarget, “start”);
RunCallbackInterface(onTweenLoopTarget, “loop”);
RunCallbackInterface(onTweenUpdateTarget, “update”);

Then we can use plugin like this way:

AiTweenEvent* pEvent = UiTween::UMGRTMoveFromToSimple(tweenName, pWidget, fromVec, toVec, actionParam.Duration, EEaseType::linear, “”);
pEvent->SetTweenStartCallback([this](AiTweenEvent* pEvent, UObject* pTarget) {
OnTweenStartImplement(pEvent, pTarget);
});
pEvent->SetTweenUpdateCallback([this](AiTweenEvent* pEvent, UObject* pTarget) {
OnTweenStartImplement(pEvent, pTarget);
});

pEvent->SetTweenLoopCallback([this](AiTweenEvent* pEvent, UObject* pTarget) {
OnTweenStartImplement(pEvent, pTarget);
});

pEvent->SetTweenCompleteCallback([this](AiTweenEvent* pEvent, UObject* pTarget) {
OnTweenStartImplement(pEvent, pTarget);
});

This is a great idea! I decided to go with delegates instead because they’re easier to use in Blueprints (which is where I generally use iTween). I’ve successfully added them to ActorMoveFromToFull and created an implementation that runs at the same time as interfaces, so now it’s just a matter of adding delegate inputs to all of the other functions and I’ll push the update. Thanks for the suggestion, dorgon!

we are: iTween v0.8.7

Changelog:
~New Features:
-Delegate system. Now users can specify function names that exist on the OnTweenStartTarget as well as the targets for update, loop and complete. If the target has a function with the same name specified, the tween will now call that function in addition to sending interface messages - existing users do not need to update to the new system as the old system still exists. This is a much more convenient way to make things happen whilst tweening and is much closer in style to iTween for Unity. Just be careful because function names are case-sensitive. Users are urged to use the new system moving forward because the old system will be phased out in time for performance reasons. Thanks to user dorgon for the suggestion!
-Added “…FunctionName” parameters to every “Full” iTween event.
-Added parser keys for “…FunctionName” parameters. You can invoke these by using the keys “osfn”, “oufn”, “olfn” and “ocfn.” They stand for “onStartFunctionName,” “onUpdate…”, “onLoop…”, and “onComplete…” respectively.
-Added OnTweenLoopTarget to all “Simple” iTween events.
~Fixes:
-iTween will no longer call OnTweenLoop when the tween finishes its last loop. Previously, if the user specified 2 loop sections maximum, the tween would call OnTweenLoop twice - once when the first loop ended and again at the end of the tween. This was not designed to happen. Now in this scenario it would be called once, at the end of the first loop section. When the second loop section ends, OnTweenComplete will be called instead.
-iTweenEvent actors now spawn where the player was when called instead of the world origin. This prevents issues when using large worlds.
-Spline operations that require a spline reconstruction now create a new spline in its place so the original spline isn’t altered.
-Spline reconstructions now account for the original spline’s tangents.
-Prevented a crash that would occur if the tween tried to destroy a spline that was already destroyed.
-Removed parser values for start/loop/update/complete targets. This doesn’t work anymore, sometimes causes crashes, and slows down the initial call.
-Fixed the OrientToPath function so that it works when using the pingpong loop type in move to spline point events and will look in the direction of travel always unless otherwise specified. This is done by making the object look to another point on the spline instead of looking at the world rotation of the spline point it’s currently at. In a future version, I’ll expose the customization options for what this point is, but for now it should work for prototyping :slight_smile: