There isn’t currently an event fired for when an animation ends. There is a place in source code where I see it could be put though (in CalculateCurrentFrame() in PaperFlipbookComponent.cpp). An alternative is that if you know how long your shield eqiup animation lasts (which shouldn’t be hard as you just divide number of frames by frames per second), when you set your shield equip you can set off a timer that will fire off an event so that when animation finishes your custom event can set flipbook to shield idle.
I’m still getting used to Z is up as well. wish there was a program override but then that would cause issues throughout I’m guessing.
There can be no proper 2D game creation without having TOTAL control over your animations.
On Finished,Is playing ,Is looping,Set looping,Goto Frame (x),Start from Frame (x) etc.
Using a timer for switching animations is just…weird!
And what about frame rate? i do not know how unreal handles time.Does it have build in Delta Time?
Because if not you could see a lot of weird stuff when frame rate is below 60fps.
I will wait for an official answer to before i start using timers but that does not change fact that you are and thank you for your help!
I think you should feel safe that unreal will provide you with what you want, eventually. Right now it doesn’t seem that those functions are in there. But I don’t think it will be too hard to implement. PaperFlipbookComponent has a variable called CachedFrameIndex which is an int which is frame that is currently playing; When game updates (yes wth deltaTime), flipbookComponent track how much time has passed and works out which frame it should be playing at that moment.
A lot of what you want could be done and I’m sure has some things coming.
I believe i found a bug.
If i want to batch change to a custom pivot point i have to double click on one of my sprites on content browser ,figure out exact X and Y pivot position write it down on a paper and go back to content browser select them all, right click,select project matrix and from there batch change pivot point. (Sweating!)
I attached 2 pictures with what happens when i change first sprite manually and what happens to rest of them after matrix batch pivot change.
Yeah, default sprite material is masked instead of translucent right now. I’ve debated back and forth on changing that. Masked has benefit of not having any sorting issues so it ‘just works’ out of box without having to touch sort priorities, but in exchange you can’t have smooth falloffs/etc…
That’s not exactly a bug, but it’s not very intuitive either. sprite pivot position is currently defined in texture space, so when using custom pivots on sprites in a sprite sheet, you can’t just type in same value for each one. I could potentially redefine it to be relative to source rectangle, but then it’ll get messed up when you adjust that interactively, hmm.
You can just use a regular texture sample in material to sample second texture for right now. Having ‘paired’ textures so you can use masks/normal maps/etc… and having it work with atlas packing too is on list for future though.
As a heads up, normal for sprites wasn’t getting generated correctly in 4.3. I’ve fixed in commit /UnrealEngine/commit/baf562eac855a1a6bcd9f404753c6ac33bdadda2, which will be in 4.4. There’ll also be a content examples map for Paper2D in 4.4, showing off things like custom materials.
[edit]
One other note: Make sure to set mobility of your sprite to Moveable if you are using lighting. There’s an outstanding bug for Static lit sprites where they show up as black (not sure why, spent some time debugging it on Friday when I fixed normal issue but didn’t get anywhere; it only affects masked lit sprites, not translucent ones).
[/edit]
Can you describe glitch you’re seeing in more detail (or try to grab a screenshot)? If you started with template then I could see fighting between movement logic that is setting jump / idle animation and your key. It’d also be helpful to post a screenshot of BP or paste C++ for your character.
I chose XZ partially to match front view, but mostly since things like gravity are still hardcoded to operate in Z in engine. There is some (mostly untested) support for XY or YZ by adjusting PaperAxisX, PaperAxisY, and PaperAxisZ, but I wouldn’t recommend trying it out (nothing in editor has been tested, it won’t affect 2D physics support in Engine, etc…). It might be made a first class feature in future, or it might get cut entirely.
I’ll try to get completion delegate exposed in 4.4, though long term I’d like to have something like an anim BP to drive flipbook animation (certainly for skeletal sprite animation it will make sense to leverage all of same work there and make those kinds of animations actually a type of UAnimationAsset).
RE: Time in UE4. Currently flipbook components handle time accumulation internally, using delta time, etc… in same way other engine components do, so they should be framerate independent, as are timers, timelines, delays, etc…
In 4.3, your best bet is to indeed use timers or delays, although you can set timer based on length of animation at least (GetTotalDuration() on flipbook asset). You could also get away with polling every frame for IsPlaying() for non-looping animations.
RE: goto frame X, etc… you can do all of that now, although everything is structured in terms of time ATM. You can do something like:
SetNewTime(FrameNumber / GetFlipbookFramerate())
I’ll add a frame-centric API to list of things to consider (in addition to existing time-centric one). For reference, here are things you can do with a flipbook component ATM (looks like there is no online API reference for classes in a , which I’ve raised with doc team).
/** Change flipbook used by instance (will reset play time to 0 if it is a new flipbook). */
UFUNCTION(BlueprintCallable, Category="Sprite")
virtual bool SetFlipbook(class UPaperFlipbook* NewFlipbook);
/** Gets flipbook used by instance. */
UFUNCTION(BlueprintPure, Category="Sprite")
virtual UPaperFlipbook* GetFlipbook();
/** Gets material used by instance */
UFUNCTION(BlueprintCallable, Category="Sprite")
UMaterialInterface* GetSpriteMaterial() const;
/** Set color of sprite */
UFUNCTION(BlueprintCallable, Category="Sprite")
void SetSpriteColor(FLinearColor NewColor);
/** Start playback of flipbook */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
void Play();
/** Start playback of flipbook from start */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
void PlayFromStart();
/** Start playback of flipbook in reverse */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
void Reverse();
/** Start playback of flipbook in reverse from end */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
void ReverseFromEnd();
/** Stop playback of flipbook */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
void Stop();
/** Get whether flipbook is playing or not. */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
bool IsPlaying() const;
/** Get whether we are reversing or not */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
bool IsReversing() const;
/** Jump to a position in flipbook. If bFireEvents is true, event functions will fire, otherwise will not. */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
void SetPlaybackPosition(float NewPosition, bool bFireEvents);
/** Get current playback position of flipbook */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
float GetPlaybackPosition() const;
/** true means we should loop, false means we should not. */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
void SetLooping(bool bNewLooping);
/** Get whether we are looping or not */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
bool IsLooping() const;
/** Sets new play rate for flipbook */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
void SetPlayRate(float NewRate);
/** Get current play rate for flipbook */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
float GetPlayRate() const;
/** Set new playback position time to use */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
void SetNewTime(float NewTime);
/** Get length of flipbook (in seconds) */
UFUNCTION(BlueprintCallable, Category="Components|Flipbook")
float GetFlipbookLength() const;
/** Get length of flipbook (in frames) */
UFUNCTION(BlueprintCallable, Category = "Components|Flipbook")
int32 GetFlipbookLengthInFrames() const;
/** Get nominal framerate that flipbook will be played back at (ignoring PlayRate), in frames per second */
UFUNCTION(BlueprintCallable, Category = "Components|Flipbook")
float GetFlipbookFramerate() const;
Quick update about flipbook replication support. I’ve added first steps in commit /UnrealEngine/commit/7b77223dd7b61f7b98a5d6103226286b6169235f, which also updates 2D C++ template. There’s still an open question of whether base component should handle client->server changes or if that should be done with an RPC in user code, but that should be decided soon.
I’ll update BP template once a build gets promoted.
How am i supposed to align my animations then? For example when transitioning from Jump—Falling—Idle—Shield Equip?
If i understood correctly you are telling us that we must enter pivot point manually for every frame and enter a different value for each?
I do not understand what you mean by adjusting them interactively will get them messed up . If you can calculate and apply a pivot point for presets (eg top-left, bottom center etc) I don’t see why it can’t be done for a custom point.
It is impossible to do manually for each sprite since we have thousands of them.
So what you are saying is that SpriteTexture is more or less a more convenient way of using a normal TextureSample? If I have my normals in corresponding spot in a separate texture, I can just connect TexCoord node to both textures?
For Flipbooks, is it TexCoord node that controls animation, meaning I just have to connect it to both SpriteTexture and corresponding TextureSample node to have them run synchronized?
Edit: After some experimentation it seems like answer is “Yes” to all above. Now I just have to figure out best way to handle need for a separate material for every atlas and flipbook. Any tips on how to do it most efficiently?
I would like to ask for some help from threads community since i do not know where else to turn for my 2D game in Unreal.
tutorials and manual are limited so i hope you dont mind me here so basic questions, but i guess if i receive answers for them it will be a good reference for newcomers as well since they will have somewhere to start.
I have almost finished all of my main characters moves and now i am ready to move on to enemy A.I .
I do not know how to even move him left or right!
In my previous game engines it was fairly easy.
In C2 it has a build in action called simulate movement(button or axis) press.So i just added a bool named"right" set it to true and then:
if bool"right" is true then simulate movement right.
On collision with “patrol block” set bool"right" false" set bool"left" true----- if bool “left” is true simulate movement left.
Just perfect for 2d!
In unity:
exact same thing but i added positive or negative velocity on x axis.
Here i am just staring screen for hours!
Cant seem to be able to find a “set velocity” command , i wish i could find a simulate movement action as well but I don’t think it is in there (i believe is a very good idea for you to implement in Paper2D since it will make basic enemy A.I a breeze) so i do not know what to do.
I watched muhammad’s tutorial in and it involved lerping, animations and A channels for a sprite to go left and right!
Heeeelp!!
And it would be super helpful if someone could do a tutorial as well on how collisions work between characters. For example player on collision with turtle play player animation ‘hit’.
Another thing that I noticed is that if I set my Tillmap sprites collisions to shrink wrap then it is impossible to snap and align them one next to another. They are 128x128 pixels in dimensions and I have slopes as well so second I try and fix collision box so my player can start assenting or descending system follows collision for snapping and not original size of png.
I am attaching a picture just to show you guys how game is shaping up.
I’m no expert on matter but have you tried “Add Movement input” node? It has to be called every tick you want enemy movement, and AFAIK class cannot be “Pawn” but should instead be “DefaultPawn”.
(I’m assuming you are using blueprints. And nice graphics BTW!)
Erm, I posted a link to a video which shows you how template works. We have literally showed you how to move a character. Staring at screen blankly will not result in your character moving.
paper2d character is inherited from character class (in fact it is pretty much a character but with a paperflipbook component). Anything you can do with a character you can do with a paper character. Maybe watch some of official epic tutorials.
We’re talking about refactoring the ‘spaces’ in sprite editor, and will probably end up redefining pivot as part of that work (which will also add ability to 1D rotate sprite in sprite editor as well, allowing more efficient texture packing). I don’t think work will make it into 4.4 though. Any existing content with a custom pivot will get updated at load to new definition.
SpriteTexture node is just an alias for a TextureSampler parameter named ‘SpriteTexture’. It’s just there so it’s a little easier to organically discover how to make a new material for use with sprites. When proper support for multiple-texture sprites come in, I’ll probably add a texture ID to node, and that’ll just change parameter name to SpriteTexture2, 3, etc…
Yeah, UVs for a sprite reflect where in the ‘base’ texture they are, so associated textures will work fine even without first class support if your sprites aren’t animated, or if they’re animated but come from a sprite sheet, with mask or normal map matching same layout.
RE: Material management: You can make mask/normalmap texture a parameter in your base material and create material instances that just update parameter for each different texture you want to use. It’s still a hassle with an extra asset per texture, but much less so than duplicating actual material logic. You could also do at runtime using MIDs (MaterialInstanceDynamic), taking an array of textures and making MIDs to use instead.
Looking pretty cool! AI logic for enemies is really not Paper2D specific. You should be able to follow along with any other AI tutorials for UE4 to get a better idea of what to do. If you’re using a Pawn derived from Character or DefaultPawn, then you can directly use AddMovementInput, but if they’re basic pawns or actors then you have more control but it’s more work too.
If you’re using a raw Pawn, you’d use GetMovementInputVector() and ConsumeMovementInputVector() in your Tick to act on added input, but for now I’d suggest working off of a APaperCharacter instead. In general I’d suggest starting a new thread for your AI questions in BP or C++ forum, depending on which you are using, so you can get more eyeballs on your question.
[QUOTE=;103025]
Erm, I posted a link to a video which shows you how template works. We have literally showed you how to move a character. Staring at screen blankly will not result in your character moving.
I was referring to an NPC and not actual main character that is controlled by us.
In 2 days and with zero knowledge of unreal and blueprints i managed to have 14 different states for my main character.Idle,run,attack,jump,double jump,falling,shield equip,shield idle,shield up down etc.
reason i was able to do that is because unreal has a very logical approach to our main controlled character.In matter of fact it is very close to C2 a 2D only HTML game engine.And that game engine is most logical and approachable thing ever.
It has build in many features that make our life easier like “Jump” or checks like"is on ground".In that department is leaps and bounds over unity where i had to implement a line cast just to check if he is touching ground and i also had to add in every playmaker state y velocity just for him to jump.
But on same time what you learned once you could apply it everywhere.So i could give my enemy A.I basic movement with exact same method i used to move my gamepad controlled character.
Here is exact opposite if i am not mistaken.You can create complex main character movement with little effort and you need a PHD in computer science to do same thing with an NPC.(I still cant get over shock of me watching muhammad using animations and lerping XD)
Thats why i suggested to to consider simulate input method.If we give a pawn ability to move (i believe it is called character in blueprints ) then why cant we remote control him?
Imagine : On button pressed “J” ----->Player jump----> delay 0.2------> enemy simulate jump.
in 2 seconds we created an enemy that interacts in our input . is just perfect for a simple 2D game.I highly doubt that super mario has any more complex A.I than that
If i am not for too much could you please do a basic video tutorial about NPC movement and interaction with our main character.It would be a life saver.