Search Unity

PowerSprite Animator - Edit your sprite animations in style

Discussion in 'Assets and Asset Store' started by PowerhoofDave, Sep 29, 2016.

  1. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    For crawl we actually had a color replacing shader to deal with those variations. There's a few options though-

    For Regular Human Basketball we had a component that got the current sprite name from base animated object in the LateUpdate function, and then using that sprite name, appended the "costume" string to it to find the final sprite to render. Eg: if the current anim frame was "walk_3" we'd render the sprite "walk_3_bighat"

    But probably the simplest is to create the animation for the first character, then duplicate it for others and drag in the new sprites. You can hold CTRL while dragging sprites over the timeline and it'll replace the existing sprites rather than inserting them, so you don't have to do re-do timing. Then you can just change which set of anims you play for each character.

    Hope that helps!
     
  2. dvdarias

    dvdarias

    Joined:
    Sep 24, 2014
    Posts:
    12
    @PowerhoofDave

    The asset looks great :) and I am considering buying it... I have just one question:
    Does it support animations that change the sprite on a child GameObject, for example in this hierarchy:

    Player < this is the game object with the Animator component
    --RotationPoint
    ----FlipAxis
    ------Sprite < this is the game object with the SpriteRenderer component

    This basically makes the path in the animation file something like:
    ...
    attribute: m_Sprite
    path: RotationPoint/FlipAxis/Sprite
    ...

    The reason I need this is because the same animation that controls the Sprite in "RotationPoint/FlipAxis/Sprite" also controls the shape of a Collider2D component in the "Player" game object so the Animator component has to be in the "Player".
     
    Last edited: Nov 10, 2019
  3. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Yep, that's supported! There's an "Advanced" dropdown in the editor with a "Path" field. You'd just put "RotationPoint/FlipAxis/Sprite" in there and it'll work.
     
  4. dvdarias

    dvdarias

    Joined:
    Sep 24, 2014
    Posts:
    12
    Done, I just brought it.
    Thanks a lot for the amazing tool Dave.
     
  5. TimNedvyga

    TimNedvyga

    Joined:
    May 18, 2015
    Posts:
    96
    Hey @PowerhoofDave, is there a way to change default shader used in Editor previews?
     
  6. dvdarias

    dvdarias

    Joined:
    Sep 24, 2014
    Posts:
    12
    Hey @PowerhoofDave

    On the current pos/rotation node implementation the updated value is a field in a Component, this is why node count and names are fixed.

    Instead of generating the animation of a component field, have you considered the idea of generating the animation of the Transform.m_LocalPosition.x/.y of a child object named like the node?

    Advantages I see of this approach:

    - It effectively tackles the limitation of 10 nodes
    - It allows custom names on each node
    - The names are explicit on the Unity Animator window
    - Unity validates the absence of the possible child nodes and gives you an explicit yellow warning in the Animator window if the user forgets to add the correctly named child GameObject
    - You can preview the position scrubbing the unity animation window
    - If you want a game object to follow the animated node you set is as a child in the editor or in code using "Transform.parent = Eye.Transform;" if dynamic or simply make a custom script like you have to do now that gets the node transform position and sets it on the current node.
    - On the current implementation, if the animator UpdateMode is set to AnimatePhysics, the way to get the last animated position of a node on the OnTriggerXXX and OnCollisionXXX events is to check if it is "controlled by a node" which is a bit hacky
    - Slightly more efficient

    Example:
    anim1.PNG

    In the generated anim the node controls a child GameObject with the name of the node.
    anim2.PNG

    Warning if the user forgets to add the child node.
    anim4.PNG

    The path of the attribute would be SpritePath+"/"+NodePreviewName
    anim3.PNG



    I am asking because you are in a way better position than myself to judge if this workflow is good? better? viable?
     
    Last edited: Nov 26, 2019
  7. Thony-D

    Thony-D

    Joined:
    Sep 9, 2018
    Posts:
    2
    Thanks so much for your response Dave. For basic color changing we are using a color shader now as well but we might end up wanting to try having costumes eventually. If you are willing, could you make the component you used for Regular Human Basketball part of the PowerAnim package or make it part of the documentation as example code for extending on the core functionality? I think it would be very useful for the rest of us who are still beginners at coding.
     
  8. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Sorry guys, missed a bunch of messages here.

    No, sorry. At some point this year I need to update the preview window at some point so you can edit while the game's running (which broke after unity 2017). And I can see if there's a more flexible way then.

    Ah cool, I honestly just never thought of doing it that way. I can see the advantages. I guess I just thought that recording a whole game object just to record X/Y and angle data would be overkill, but then behind the scenes it's no different anyway. I probably won't change things in the short term now that it's in and we're using it, but it's definitely a nicer way of doing it I could add later.


    The solution I had for regular human basketball is really very game specific so wouldn't translate I'm afraid. It's all tied up with game code and really only worked with the workflow our artist had for exporting art (on different layers, etc), so not really very shareable. It was also a pretty clunky way of doing it, but we only had about 5 animations so it worked for that game.
     
  9. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    Hi, i bought the asset, got the following errors. Iam on 2019.3

     
  10. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Thanks zh4r0naX. I haven't tested on 2019.3 yet, something might have changed and need fixing. I'll look into it and get back to you.

    Edit: I'm not getting any errors in my own test project @zh4r0naX. Can I get some more details on how he thing you're animating is set up and the default anim that you're trying to play? Does the powersprite animator demo scene work?
     
    Last edited: Feb 7, 2020
  11. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71

    Thank you for the quick reply. Somehow it is working now. If i run into the issue i would message you again. Maybe some Unity bug, idk.

    It just happens for a single animation file, if i create a new animation and then set it up it works. If i find the cause of this i will tell you. But for now it seems to be working fine. Thank you for the great tool
     
    Last edited: Feb 8, 2020
  12. Luthdraco

    Luthdraco

    Joined:
    Sep 12, 2019
    Posts:
    3
    I have been using the tool for some months now and I sometimes even forget that Unity has its own animation window, tough I'd still like to see that feature I mentioned here previously of having a window to select animations tied to a gameobject.

    That said from a lot of usage I have encountered some annoying bugs, all of them relating to the name field where we type the name of events to be triggered:

    1) When the auto-complete windows pops up, if we click on an event name in the list there nothing happens and instead the click registers on the animation timeline, removing focus of our current event that we were editing.
    2) When we type the first letter of an event name and the auto-complete window shows up, we can press enter to place the event name in the field. But if after that we click for example in another .anim and then return to the animation that we used the auto-complete, we see that it didn't register and instead the event has only the single letter that we typed in at first.
    3) There was actually another bug relating the event names not properly registering due to the user clicking somewhere else, but I forgot how to reproduce it so if/when I happen upon it again I'll report it here.

    So generally speaking, the event name field is quite finicky and it's "losing" the string or not properly saving what we typed in some cases (even when pressing enter or control+s, etc). It would be really great to have a small bugfix update for those issues.

    The tool is really handy and one of the best values when it comes to assets that I've bought for unity, thanks for the good work.
     
  13. CurtisMcGill

    CurtisMcGill

    Joined:
    Aug 7, 2012
    Posts:
    67
    Just picked up this package and would love to see a youtube video on how do you use the event/parameter, send upwards/require receiver? I am not sure what to put in for values and what script should process events.

    I did get the following to work:
    I added the runner.cs script and in my animation added an event.

    Typed in method name of Event "Attack"
    Parameter string, typed "AniDone".
    Clicked on the Required Receiver.

    In the runner.cs added the following method.
    public void Attack(string message) {}
     
    Last edited: Mar 9, 2020
  14. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Following up the above question, does SpriteAnim actually triggers the animation events?
     
  15. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Oh, I'm really sorry everyone! For some reason I didn't get notifications until today about these posts!

    And yes, you're quite right, events are bugged since the last update! If you type the full event name and ignore the autocomplete it still works, but otherwise the event name isn't being saved correctly.

    I'll fix that ASAP, really sorry!

    I think the documentation pdf explains it. But what you did is correct. If you have "SendUpwards" ticked, you can put the function in any monobehaviour on the same game object as your SpriteAnim component, or any parent of it.

    They do trigger, but yeah, the autocomplete feature broke them, so type them out fully each time to get around that (until I fix it)
     
    Luthdraco likes this.
  16. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I was also wondering.. since the SpriteAnim component effectively uses Animator to do its job, does it respect the animator's setting for culling?
     
  17. Gus3D

    Gus3D

    Joined:
    Dec 1, 2014
    Posts:
    27
    This is freaking amazing. I can't believe I've been working with Unity sprites for 6 years without this. Absolute game changer.

    Any plans on getting a node's preview sprite to actually rotate according to the angle you put in?
     
  18. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    I've got a fix for that bug with anim tags/events. Unity can take a little while to approve updates, so if anyone needs it immediately DM me and I'll send you a link.

    Haven't tested that, but it should respect the setting, can't see why not. My SpriteAnim and AnimNodes components don't have update functions, so they won't be running anyway.

    I must admit when I see people doing frame-by-frame animation without it I cringe a bit :p
    I have to look at rotating them, I need to see if I can get the viewport working while the game is running again anyway (it worked pre-2017, which was really handy).

    While I'm updating it I might add a couple of simple helper scripts for getting people started attaching nodes and using anim tags.
     
    Last edited: May 21, 2020
    Luthdraco likes this.
  19. Luthdraco

    Luthdraco

    Joined:
    Sep 12, 2019
    Posts:
    3
    Hey Dave! I can confirm the fixes for the animation events name box! Thank you very much for the update!

    But as I mentioned in the DM's, there is now a bug/mismatch in the theme for powersprite. I use the light theme and I think some of the darker shades of colors carried over from your dark theme, which makes the controls look rather unpleasant to work with. I'd be really thankful for a fix for those too!
     
  20. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    The new update is up! Here's what changed:
    • Added simple function for attaching things to your Anim Nodes
    • Preview/Editing now works while the game is running
    • Attachment preview sprite now shows rotation
    • Fleshed out the Demo Scene with examples of Anim Nodes, Events and more complex playback
    • Anim event autocomplete actually working now!
    • Fixed some layout issues with Unity 2019.3+

    Note for Unity 2019.1 and 2019.2 users
    There's a bug in this version that stops the preview camera from having a transparent background. The editor still works, it's just a lot uglier. It's fixed again in 2019.3. If you need to stay with this version of unity, DM me and I'll sort you out :)
     
    Last edited: May 26, 2020
    NotaNaN and Gus3D like this.
  21. Gus3D

    Gus3D

    Joined:
    Dec 1, 2014
    Posts:
    27
    @PowerhoofDave

    A-M-A-Z-I-N-G

    What do I do with all this power????
     
    NotaNaN and PowerhoofDave like this.
  22. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Awesome, looking forward to that update.

    One further question/request: I noticed that There is a SpriteAnimController.controller and a SpriteAnimPlaceholder.anim located in the Resources folder. Are those two files actually necessary, I can't find them being mentioned in the documentation?
    If they are not necessary I'd like to delete them and ask I you maybe change the name of the folder alltogether since everything inside any "Resources"-folder will get inside the build of the game no matter if needed or not, which will increase the size of the build :)
     
  23. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Those are used for the SpriteAnim component. Internally, that controller is shared between all objects that use the component (rather than each animated object needing a separate SpriteAnimController), and the animation is an empty one overridden with the one you want to play. If you're only using the Animation editor and not the SpriteAnim script, it's safe to delete it/not import it from the package, though it's just a controller with a single state and an empty animation, so in the build it's pretty teeny tiny.
     
    BTStone likes this.
  24. NikoBay

    NikoBay

    Joined:
    Aug 15, 2018
    Posts:
    39
    Does Animator Editor support editing other attributes in Inspector panel such as Collider, Position...? Something like the builtin Animation does when we click (Red button) to start editing. I could not find how to change collider at specific frame.
     
  25. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Hi Niko, I answered on twitter already, but echoing my answer here-

    PowerSprite Animator doesn't support animating other attributes, it's outside the scope of the tool, so not something I'm planning to add. But you can use unity's animator in conjunction with PSA. (eg. Set up your sprite animation in PSA then switch over to unity's editor for the rest.) Though I believe unity gets confused when you have the same animation open in both editors at the same time ;)

    You can also potentially use the Anim Nodes or Anim Events to control various other properties via a custom script, if that makes sense for your implementation & workflow.
     
  26. nekolyst

    nekolyst

    Joined:
    Mar 12, 2018
    Posts:
    23
    Hi Dave,
    Nice asset! It's a lifesaver!

    I have one thing to ask, do you planning to add a "flip" function in this asset?
    Some times I just want to turn sprite to another side and don't need to switch to unity's animation.

    Thanks!
     
  27. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    What's wrong with using flip function on the SpriteRenderer?
     
  28. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    It's not something I'm planning on adding. Basically anything outside frames, nodes and events, I'm reluctant to add, since I don't know where I'd draw the line at what you can animate and what you cant (and I'd just end up re-doing unity's animator completely!)

    Usually Id flip it in code, by scaling the x axis by -1, or using the SpriteRenderer Flip like castor76 mentioned. I haven't needed to animate flipping so far, since usually I need to know in code which direction a character's facing anyway to get them moving the other direction, etc.

    But if you want to have an animation where the sprites on just a few frames are reversed, then, yeah, you just have to either use unity's animator, add a flipped version of the sprite, or add a "flip" function to your script, and call it using an anim event.
     
  29. nekolyst

    nekolyst

    Joined:
    Mar 12, 2018
    Posts:
    23
    Thanks for the reply!
    Okay, I understand your mean.

    In my case, the game is a top-down view and the character has four directions. I use Blend Tree to control which animation(direction) will play. And the PowerSprite Animator is very convenient. I can edit animation directly. So I just ask if can flip the sprite in this tool, then I can duplicate the right face animation and change the direction to left quickly, and put the animation into the blend tree.

    Anyway, I will switch to unity's animation and set the SpriteRenderder property.

    Thanks a lot!
     
    Last edited: Jul 28, 2020
  30. NikoBay

    NikoBay

    Joined:
    Aug 15, 2018
    Posts:
    39
    I have a question about expanding this tool.
    I'd like to add Hitbox Editing into the tool for frame based actions.
    Do you guys know any ways to visualize the hitbox edit and save them for each and every specific frames? Any sources/hints are appreciated.
     
    w409544041 likes this.
  31. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Hi NikoBay. I assume you mean a streamlined version of Unity's existing sprite collider editor that's built into PSA?
    I can see why that'd be pretty useful, but It'd be a fair chunk of work and so I think it's unlikely to be something I'll find time for.

    If you were more meaning something for attacks, rather than the object's own collision, you could attach the attack objects to a sprite anim node, and use a debug preview sprite to visualise it. For melee attacks we tend to use anim events for turning on/off 'damage' collider objects that we attach to a node, that could be more what you're after.
     
  32. NikoBay

    NikoBay

    Joined:
    Aug 15, 2018
    Posts:
    39
    Tks, Dave. I'm more on the seeking for advice how to expand the tool than asking for expansion. Maybe I'll try to work with node as you suggested.
    Also, might I ask if you guys are using Unity builtin mechanim for animations of your projects (Acid Knife, Drifter..) or something else?
    "For melee attacks we tend to use anim events for turning on/off 'damage' collider objects that we attach to a node, that could be more what you're after." Is this how you do for Acid Knife melee attack? The project is very cool and inspiring.
     
    Last edited: Sep 23, 2020
  33. Djaydino

    Djaydino

    Joined:
    Aug 19, 2012
    Posts:
    48
    Hi.
    Is there any in depth info on the event usage.
    I made Playmaker actions for this asset, but i want to support events as well, but i cant find much info or a video on the usage.
    Where can i get more info (do i need to place a component on the object etc)
     
  34. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    I'm not familiar with Playmaker Actions, but there's more info on events in the PSA manual here: http://powerhoof.com/public/powerspriteanimator/PowerSpriteAnimator-Manual.pdf

    By default the events are the same as Unity's built in Animator Events. When unity hits an event during anim playback, it looks in scripts attached to the animated object for a function that matches the name of the event, and calls that function.

    However I add some additional features such as "send upwards" tickbox that only work if the SpriteAnimEventHandler, or SpriteAnim component is added to the object.
     
  35. lorewap3

    lorewap3

    Joined:
    Jun 24, 2020
    Posts:
    58
    Hi Dave! I got the animator and it's working wonderfully! It's a great asset.

    I have a question for you, though. Is there a way to freeze the length of the animation? I'm creating animations that are looping based on various musical beat increments. I'm doing this using Koreographer, and the method that's easiest to incorporate into it creating the animations with an exact 1 sec length. Then, using Koreographer API and the settings I choose it will manipulate that animation to be the exact length desired (1/4 note, 1/2 note, 1/8 note, etc).

    I know this is kind of opposite the way animations are normally done, so I wouldn't be surprised if this option doesn't exist in power animator. But basically I want to be able to 'lock' the frame length so that adjusting the frame lengths will still keep the last frame's end time exactly what I set it to.

    Perhaps a key modifier like ctrl when you click the line after the last frame? It highlights the line in red or blue or something denoted it's locked. Now when any other frames are adjusted it auto expands/shrinks the last frame to stay within the desired length. A more robust solution would be to add the ability to lock any frame, but that's beyond what I need. If I could get the ability to just lock that last frame so I don't have to keep resetting the length that would be perfect!

    Thanks Dave!
    Will
     
  36. lorewap3

    lorewap3

    Joined:
    Jun 24, 2020
    Posts:
    58
    Hey guys. Forgive me for bothering you again. I have a different request, but loosely related to the one above.

    I'm trying to create a editor function that will loop through all the animation clips I have selected in my assets folder and set all of their lengths to 1 sec (because of the beat increment looping mentioned above). The algorithm you guys have in PowerSprite Animator works very well. I found the code and am trying to duplicate it for a static function, but I'm getting lost in the code that applies the changes as it's rebuilding the entire animation.

    What would be the best way to extract that functionality? I've gotten this far but I'm hoping you guys might be able to guide me a little to filling in the missing pieces.

    Code (CSharp):
    1.        [Button("Set Animation Lengths to 1")]
    2.         public static void SetAnimationLengthsTo1()
    3.         {
    4.            
    5.             foreach (var aniClip in Selection.GetFiltered<AnimationClip>(SelectionMode.Assets))
    6.             {
    7.                
    8.  
    9.                 float oldLength = Utils.Snap(aniClip.length, 0.001f);
    10.                 float newLength = Utils.Snap(1f, 0.001f);
    11.                 float newFramerate;
    12.  
    13.                 if (Mathf.Approximately(newLength, oldLength) == false && newLength > 0)
    14.                 {
    15.                     newFramerate = Mathf.Max(Utils.Snap((aniClip.frameRate * (aniClip.length / newLength)), 1), 1);
    16.                     ChangeFrameRate(aniClip, newFramerate, true);
    17.                 }
    18.             }
    19.         }
    20.  
    21.  
    22.         private static void ChangeFrameRate(AnimationClip aniClip, float newFramerate, bool preserveTiming)
    23.         {
    24.             Undo.RecordObject(aniClip, aniClip.name + " clip set to length of 1 sec");
    25.  
    26.             // Scale each frame (if preserving timing) and clamp to closest sample time
    27.             float minFrameTime = 1.0f / newFramerate;
    28.             float scale = preserveTiming ? 1.0f : (aniClip.frameRate / newFramerate);
    29.            
    30.             //foreach (AnimFrame frame in m_frames)
    31.             //{
    32.             //   frame.m_length = Mathf.Max(Utils.Snap(frame.m_length * scale, minFrameTime), minFrameTime);
    33.             //}
    34.  
    35.             aniClip.frameRate = newFramerate;
    36.             //RecalcFrameTimes();
    37.             //ApplyChanges();
    38.         }
    Thank you so much!
     
  37. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Hi @lorewap3,
    Sorry for the slow reply, was finishing up a gamejam ;)

    Interesting use case! I think it's too project specific for me to add as a feature. You can set the animation length on the panel on the right, and it'll scale your framerate so the final animation matches that time. So you could tweak your frame lengths, then set that to 1 again. Maybe more fiddly than you're hoping though.

    As for the second bit of code... I don't think yo u can just change the framerate/samplerate. Unity doesn't actually use this except in its editor, so changing it doesn't change the length of an animation. My code actually modifies the frame timings as well as changing the sample rate. So you probably need to actually load the anim in PSA, and acually call the ChangeFrameRate. Probably easiest just to hack up my code to do it-

    In your loop, you could do :
    Code (CSharp):
    1. SpriteAnimator psa = EditorWindow.GetWindow<SpriteAnimator>();
    2. Selection.activeObject = aniClip;
    3. psa.OnSelectionChange(); // load the anim
    4. psa.ChangeFrameRate(10000, false); // since unity expects framerate to be whole number, if we set it high first we get more accuracy in below calcualation.
    5. float newLength = 1;
    6. float newFramerate = Mathf.Max(Utils.Snap( (m_clip.frameRate * (m_clip.length/newLength)), 1 ), 1 );
    7. psa.ChangeFrameRate(newFramerate, true);
    You'll need to add
    using PowerTools.Anim;
    and make some of the above function in SpriteAnimator public (OnSelectionChange, ChangeFrameRate)

    Maaaybe that'll work? Let me know!
     
  38. lorewap3

    lorewap3

    Joined:
    Jun 24, 2020
    Posts:
    58
    Hi @PowerhoofDave ,

    Thanks for getting back to me! You're right it is a very specific use case. Going back with the developer of Koreographer I came up with a much more flexible solution than initially thought possible. I was able to code it to be length agnostic so the 1sec length is no longer required. Which also removed the need for the utility to adjust lengths en masse.

    However, I do have another question for you! I'm working on a custom game manager window to manage assets. I just finished a window that allows setting the animation loop of states based on note lengths (1/8, 1/4, 1/2 note, etc). Here's a screenshot to illustrate:
    upload_2020-12-6_18-27-57.png

    The next window on it will be to attach particle system prefabs to each of the nodes setup in PSA. The UI will look alot like the above. It displays all the states, and under each state, all of the nodes set in that state. Each node will have at least a prefab variable (and probably more eventually) that can be set.

    But I'm a little confused as to where exactly I can access the node data in Edit Mode. I know the node data is in the animation timeline, but what class reads that data and feeds it to the Sprite Anim Nodes component attached to the game object in the scene? That's the part I can't figure out. This is for an editor window, so is there a utility function that will allow me to get the node data if I pass it an animator and a state name?

    That's what the window above does. It reads the prefab set, gets the animator, and gets all the state names from that.

    Any assistance would be greatly appreciated! Thanks Dave!

    Will
     
    Last edited: Dec 7, 2020
  39. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    It's unity's animation system that actually changes the node position values in the SpriteAnimNodes component on a gameobject. Each of those position values is "animated" in the same way unity animates anything else.

    So the only way to get that data out in an editor is to parse the data from the animations themselves (as I do in PSA when I load an animations).

    I'm not 100% clear on how your tool is meant to be used, but hopefully that make sense enough to gets you moving in the right direction :)
     
  40. lorewap3

    lorewap3

    Joined:
    Jun 24, 2020
    Posts:
    58
    Hey @PowerhoofDave , thanks for the reply. You'll have to forgive my Unity noobness. I'm new to Unity from GM2 so I can get ahead of myself. I know any component parameters can be animated, but I guess the confusing part to me was how it mapped from Sprite Anim Nodes.Node 0 property in the Animation window to the variable m_node0 in the SpriteAnimNodes class. I know Unity camelcases/pascalcases automatically, but is the m_ prefix another thing Unity auto does?

    Would you mind helping me understand how your Editor reads the node data? I've been reading your SpriteAnimatorNodes.cs class trying to figure it out and it does alot more than just read the node data which is getting me a little lost. Specifically ReadNodesFromClip.

    Maybe it'll help if I clarify the tool. My project is currently more of a content creation tool for making music videos than a game at the moment. I'm building a library of organisms (fit better than character as these could include plantlife) that react to music. The screenshot in the last post is synchronizing animator states to a beat. The FernGreen's IDLE state above is set to 1/4 notes with OutSine easing. So for ex. in a 128 bpm song playing every beat (1/4 note) the IDLE state will loop exactly 1 time, and will do so using an OutSine easing curve (rather than linear).

    What I want to do in this next window is a similar thing but for nodes. These are intended for particle generation. Suppose the FernGreen organism above and I set the nodes like this:
    upload_2020-12-7_18-28-43.png
    I setup some simple particle systems on each:
    Screenshot 2020-12-07 182703.png

    These particle systems will eventually be driven by note data sent from Koreographer. Eventually I'll have a library of these particle system setups as prefabs so they can be re-used in other organisms. This is what the window I'm trying to create with the nodes is all about. I want one spot where I can go and switch out particle prefabs as well as tweak parameters for each in one spot.

    So I don't really need any of the node data, just the superficial information of how many nodes are in a certain animation clip, so that I can create an editor window that will allow me to attach additional metadata to those nodes.

    I guess my base question is, how can I copy your ReadNodesFromClip() function from SpriteAnimatorNodes and strip it to just give me the number of nodes if I pass it an animation clip?

    Because you're doing so much more than I need, I'm just having a hard time figuring it out. The ReadNodesToKeyFrameReadInData seems to be where you're reading it? Then there's the EditorCurveBinding array variables that I don't understand how they come into play. But I don't really need to understand any of that and I don't want to waste anymore of your time than I have, but any info on what I should be focusing on would be helpful.

    Again I really just want a utility function that I can pass an animationclip and it will give me the number of nodes it has. If I could get something like that that would be all I'd need!

    Thanks again Dave!
    Will
     
  41. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Yes, the m_ prefix is a naming convention a lot of coders do to differentiate between local and member variables (m_ being member). Unity handles nicely displays these without the m_ (and with camel case seperated as you said)

    Yeah, it's super complicated, I had to work out how to read data from anims using unity documentation (eg https://docs.unity3d.com/ScriptReference/EditorCurveBinding.html). It's not a simple thing unfortunately.

    I think I understand more what you're after now though, though I don't think there's a super simple way. At run time the way I test for "is there a node" at runtime is to check if its position is 0,0 :p

    Your simple option is to be able to manually set the number of nodes in your tool per organism, since you know how many you've added in the animation.
    Otherwise, maybe try something like this using the AnimationUtillity.GetCurveBindings() function:
    Code (CSharp):
    1.  
    2.  
    3.         int numNodes = 0;
    4.         EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings(myClip);
    5.         for ( int i = 0; i < 10; ++i )
    6.         {
    7.             string propertyName = bindings[i].propertyName;
    8.             if ( propertyName.StartsWith("m_node") && propertyName.EndsWith(".x") )
    9.                 numNodes++;    
    10.         }
    11.  
    No idea if that would work though, just a guess!
     
  42. lorewap3

    lorewap3

    Joined:
    Jun 24, 2020
    Posts:
    58
    Good to know! It's conventions like this that's hard to learn about in a vacuum.

    It worked! Well once I changed the 10 to bindings.Length, but yes this is exactly what I needed!
    upload_2020-12-8_20-18-58.png
    The Emitter class is a stub at the moment, but you get the idea. The lists are synchronized OnInit with the nodes in the clips so it will match up to the number of nodes. I know it might seem like overkill but it'll make it easier to only show the emitters that need to be set up.

    Thanks for being patient with me Dave! I know my questions were rudimentary so I'm extremely appreciative of you spending the time to help me out. I hope your game jam went great two weekends ago! Oh and I love Crawl!

    Will
     
  43. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Awesome, glad you got it sorted. What you're doing looks great btw, little custom tools like you're making are great. And your questions are really very advanced, not rudimentary at all ;)

    The jam was good too, thanks, though still feel like I'm recovering ha ha
     
  44. NikoBay

    NikoBay

    Joined:
    Aug 15, 2018
    Posts:
    39
    Hi Dave,

    Is there any way to check in which frames a specific node is used?

    For example: I use node 0 at frame [1, 2, 3, 4] in total 10 frames of a clip. When playing that clip, is there any way I can know at a certain frame, node 0 is being used or not?

    Use means I edit (drag, rotate) a node and make it clear circle in preview panel, compared to transparent circle of ones that were not touched. See below
    Screen Shot 2021-02-23 at 11.58.26 AM.png Screen Shot 2021-02-23 at 11.58.30 AM.png

    I think in SpriteAnimatorNodes, we know when a node is overriden in current frame or not and change its size and alpha for preview. But I don't know how to get this info.


    Best Regards
     
    Last edited: Feb 23, 2021
  45. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    At runtime, the only way I know is to check if it changed from its previous position/angle when you update, since nodes are saved as just a curve in the animation.

    It's a unity limitation that you can't get data from an animation at runtime (without playing the animation) afaik.
     
  46. NikoBay

    NikoBay

    Joined:
    Aug 15, 2018
    Posts:
    39
    Tks Dave,

    I planned to use it for my hitBox position and on/off state.
    I've figured out a way already.
    Set "hitBox" node in every frame that is supposed off to vector2.zero. Then checking if the getPosition from Nodes has x and y = .0001f to determine if hitBox is online on this frame or not.

    Rgds

    PS. The acid knife looks really cool. Good love to know how it works with animation. Is it also using PowerSprite?
     
  47. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Great. The other way is to use animation events, we use them heavily for things like turning on/off hitboxes. And yes, we're using PSA for Acid Knife :)
     
    NikoBay likes this.
  48. ExtraCat

    ExtraCat

    Joined:
    Aug 30, 2019
    Posts:
    52
    Hello, I've been using Power Animator for a while, and it works great except cases where I tried to use Addressables to provide AnimationClip to the SpriteAnim script from your asset.

    I discovered that unloading the clip played by SpriteAnim script via Addressables.Release(clip) crashes the build (not the editor) when it tries to play next clip. Even if the previous clip was stopped.

    I looked into your Play() code, and I believe this is the reason:
    Code (CSharp):
    1.         if (m_animator.enabled == false)
    2.             m_animator.enabled = true;
    happens earlier there than

    Code (CSharp):
    1.             m_clipPairList[0] = new KeyValuePair<AnimationClip, AnimationClip>(m_clipPairList[0].Key, anim);
    2.             m_controller.ApplyOverrides(m_clipPairList);
    meaning even if Animation clip that Play() played previously was unloaded from memory, Play() still will try to play it again for a brief moment before loading the new clip. Well, or at very least that's how I understand it.

    After I moved m_animator enabling to happen after ApplyOverrides, crashes stopped. Perhaps you can add this change to the next release, or improve my solution somehow.
     
    Last edited: Mar 17, 2021
  49. PowerhoofDave

    PowerhoofDave

    Joined:
    Jun 26, 2015
    Posts:
    75
    Hey ExtraCat, Thanks for that! I hadn't used addressables yet, so didn't know about the issue, but your explanation makes sense. I'll put in the change you made and see if it causes any other issues, but I think it's probably good!
     
  50. Alucardjh

    Alucardjh

    Joined:
    Jun 4, 2015
    Posts:
    6
    Hi is there any video tutorial for this Power Sprite feature? Thanks