Search Unity

Smooth Moves - 2D Skeletal Animation

Discussion in 'Assets and Asset Store' started by echo17, Feb 20, 2012.

  1. Cutedge242

    Cutedge242

    Joined:
    Nov 20, 2012
    Posts:
    9
    I'm having an issue with swapping textures. Basically, in order to save our artists some time I had realized that you don't have to set the Atlas Key and Texture Key in each keyframe, so we went ahead and turned them off. For the normal textures that are set in the animations this is perfectly fine and doesn't present any problems. However, when I do the texture swap and then play animations, frames that do not have the atlas and texture set in the keyframe don't always get the swapped texture and instead reference the original texture or at least the original texture atlas. The end result is that I get kind of garbled looked textures on the bones because it seems like it is not updating the texture atlas references.

    Is there a programatic solution to this or should I just turn the texture and atlas key settings back on for all the keyframes?
     
  2. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I definitely would not recommend setting texture keyframes for every frame. This will eat a ton of memory and slow down the processing at runtime.

    Just a general diagnosis: If you have multiple clips playing on an animation (fading, blending, etc) then each clip will fire triggers to set the texture. If these clips have different textures set for a bone, then you will see the clips competing with each other to play the correct texture. This is especially tricky with cross fades between clips on the same layer since SmoothMoves will not know which texture to give priority to. If you are mixing, be sure one of your clips is on a higher layer. Higher layers have priority when determining which texture changes to fire.

    If you want a more specific diagnosis of your particular project, you can send me an email at: support@echo17.com with your project zipped up. Be sure to include an example scene with instructions on how to reproduce the problem.
     
  3. danboutros

    danboutros

    Joined:
    Mar 26, 2012
    Posts:
    32
    Question for Layne;

    We have an animation that at the end, tints the color of the item green, using your blend anim options. It looks and works fine in the SM editor.

    However, when we move to run time, the tint does not appear. Any thoughts as to why that may be?

    Cheers,


    Dan
     
  4. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Take a look at the link in my FAQ:
    http://www.echo17.com/forum/index.php?topic=247.msg353#msg353
     
  5. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Check out Kontrabida's latest animation demo made with SmoothMoves!

     
  6. danboutros

    danboutros

    Joined:
    Mar 26, 2012
    Posts:
    32
    Thank you kind sir! GREAT FAQ btw.

    I'd like to ask if you could add the issue where character art scales outside of original boundaries when rebuilding atlases and then animations through smoothmoves, and what settings to look for.
     
  7. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    You're welcome!

    For clarification, are you talking about rebuilding your animations after you rebuild your atlases?
     
  8. danboutros

    danboutros

    Joined:
    Mar 26, 2012
    Posts:
    32
    I am indeed. And what happens when settings are missed / ignored and the art scales out of its intended look to weirdly huge and clipped on each bone.
     
  9. danthat

    danthat

    Joined:
    Aug 1, 2012
    Posts:
    25
    Hello! I'm having an issue with bone images not updating quickly enough. Is there a way to force SmoothMoves to refresh which images it should be using on each bone?

    For example - when climbing up and down ladders, my "climbing" BoneAnimation swaps the Head bone texture to the back of his head, and the Torso bone texture to show his back. When getting off the ladder, and resetting to an Idle animation, it plays the anim straight away, but using the Climbing textures, which are then seemingly fixed over the course of a couple of seconds. This leads to the character looking very odd.

    Any suggestions? Really I could just use a boneAnimation.UpdateImages() function to call when suddenly flipping from one to the next.

    ??

    Any help much appreciated :)
     
  10. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    There are probably several solutions to this, but without seeing how you've structured your animations specifically, I'll just give you some general ideas:

    - Try stopping the the ladder climbing animation explicitly when leaving the ladder and before playing your idle animation:

    Code (csharp):
    1.  
    2.  
    3. BoneAnimation boneAnimation;
    4.  
    5. boneAnimation.Stop("Climb");
    6. boneAnimation.Play("Idle");
    7.  
    8.  
    - If you are cross fading animations, you may want to switch to using intermediate animations. See my video tutorial:



    - If you have your climb and idle animations on different layers or are mixing, you may need to call a new mixed animation to switch your textures back to a different state.

    If this doesn't help, you can send me your project zipped up to: support@echo17.com and I'll take a look
     
  11. danthat

    danthat

    Joined:
    Aug 1, 2012
    Posts:
    25
    Thanks, I'll plug these in now :)

    EDIT: excitingly, trick #1 has fixed it! Thanks :)
     
    Last edited: Mar 1, 2013
  12. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I've created a link on my SmoothMoves page to the older knight animation project. The asset files are from SmoothMoves 1.11.1, but the runtime dll is upgraded to version 2.1.0. If you want to modify or create animations, you'll need your copy of the SmoothMoves_Editor.dll from version 2.1.0.

    http://echo17.com/smoothmoves.html under "Extra Goodies"
     
  13. danboutros

    danboutros

    Joined:
    Mar 26, 2012
    Posts:
    32
    Hi Layne - question about using color blends as a communication for a state change.

    For example, let's say a character has many animations and they can be hit during all of them, but you don't wish to change their animated pose, but rather tint them red as they are hit.

    I assume making a Red flash version of each animation pose would be too costly / impractical and that there is a smarter way to do this.

    What would you advise in this case to achieve that affect?
     
  14. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,362
    Hi

    I have a question

    I try to put a Smoothmoves animation as a prefab in ORK RPG kit enemies and when i attach a character controller to the prefab, it will not update the texture animations (texture changes) because it seems Bone animator is not running (even though it appears in the list)

    When i dont attach character controller to the prefab, the animated texture change runs fine, but the ORK does not work because it needs that character controller to support the AI movement

    Are the two incompatible or do i need a different setup ?

    Thanks
     
    Last edited: Mar 4, 2013
  15. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I've actually put in some functions in the BoneAnimation script to handle this very situation. Check out FlashBoneColor, StopFlashingBoneColor, StopAllFlashingBoneColors in the API here.

    When flashing, you can set the starting color/blend weight, ending color/blend weight, duration of each flash, the number of times to flash, and whether to restore the color when done.

    [EDIT]

    I should note that you can also do this yourself if you don't like the flashing implementation using SetBoneColor and your own script to handle what color to set. You can update the color in the Update or LateUpdate function in your script. The flashing functions were a generic solution to most cases, but there is a lot of freedom if you like to code. :)

    [/EDIT]
     
    Last edited: Mar 5, 2013
  16. Amitloaf

    Amitloaf

    Joined:
    Jan 30, 2012
    Posts:
    97
    There's a small bug that you might want to fix :) In the animation editor, if i flip one of the bones on the horizontal axis (Like the chef leg in the example when he walks - using "-1" on the x axis and "1" on the y), using the diagonal handle to scale it on both axes it doesn't work correctly, it enlarges on one axis and makes the other one smaller.
     
  17. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I am not familiar with the ORK RPG kit, so I can't comment on compatibility, but SmoothMoves should work with any plugin as long as you have your game object hierarchy correct. I generally put my animations on their own game object as a child of the object that will control them. In other words, I try to avoid putting other components like character controllers or third party scripts on the same game object as the boneanimation. As far as prefab issues, please see this FAQ for more information:

    http://www.echo17.com/forum/index.php?topic=247.msg360#msg360
     
  18. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Thanks, I'll add this to my list of fixes!
     
  19. Amitloaf

    Amitloaf

    Joined:
    Jan 30, 2012
    Posts:
    97
    Thank you! Also I have a small bug i'm not sure about.
    I have an animation with a looping "Stand" animation. When clicked it crossfades to "Dance" animation and one line after that is PlayQueued back to "Stand".
    After I click on it, it dances and the second the animation is over, before stand animation is playing again, i say an error log saying "dt >= 0" from Animation.cpp line 1812. It doesn't actually affect anything visibly but that log might indicate something is wrong.
    I have the latest version of smoothmoves and it's a brand new project.
     
  20. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    That's actually an error from the Unity animation system. It occurs when you try to cross fade or blend an animation in a time span that is shorter than the duration of the clip. This can happen if you are changing states quickly.

    It seems to be pretty harmless and doesn't affect the game play at all. If you are getting it a lot in the editor, you'll need to turn off the "Error Pause" setting in the console window.
     
  21. Amitloaf

    Amitloaf

    Joined:
    Jan 30, 2012
    Posts:
    97
    Actually both animations are about 20 frames in 5fps and it finishes the first one before going to loop the second, so i'm not sure why it happens.

    Edit: Just checked, if I change the second animation from PlayQueued to CrossFadeQueued, it doesn't throw that error.
     
  22. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Yeah, Unity's dt>=0 error isn't accessible, so there's no way to trap for it in code. The only time I've seen it happen is when I try to fade an animation and then switch quickly to another animation before the first is done. Again, it's a harmless error that doesn't cause any problems in a final build. I wish Unity would switch this to a warning instead of an error to prevent editor pauses.

    Good to hear!
     
  23. echoic

    echoic

    Joined:
    Apr 29, 2011
    Posts:
    91
    Hello,

    I bought Smooth Moves a while ago and have loved it since. I've been trying to figure out how to simply swap a sprite texture from code. I know there is code for swapping a boneanimation texture, but the items I'm dealing with are not animated. Please let me know how I can go about swapping a sprite texture. Thank you!
     
  24. echoic

    echoic

    Joined:
    Apr 29, 2011
    Posts:
    91
    I've tried to apply a new texture to an outside gameObject Sprite using the following:

    var sprite : SmoothMoves.Sprite = mainObject.GetComponent(Sprite);
    var atlas : SmoothMoves.TextureAtlas = mainObject.GetComponent(TextureAtlas);

    sprite.SetTextureGUID(atlas.GetTextureGUIDFromName("newTexture"));


    I'm getting the following errors:

    GetComponent requires that the requested component ’TextureAtlas’ derives from MonoBehaviour or Component or is an interface.

    Object reference not set to an instance of an object.

    If anyone could offer help it would be much appreciated.
     
  25. tinoh

    tinoh

    Joined:
    Feb 21, 2013
    Posts:
    28
    Hi,

    I am considering buying smooth moves for our project. I think it looks great. Can anyone confirm that it will work with the following project environment:

    Export targets:
    iOS, Flash, Web

    Other assets:
    2D toolkit

    Are there any known incompatibilities? I read somewhere (old post) about problems with flash export. Are they solved?
     
  26. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    You can reference the atlas of the sprite directly. Try this:


    Code (csharp):
    1.        
    2.  
    3.     sprite.SetTextureGUID(sprite.atlas.GetTextureGUIDFromName ("newTexture"));
    4.  
    5.  
    FYI, in the next major release there will be a function to set a sprite by name without having to translate to a guid first.
     
    Last edited: Mar 8, 2013
  27. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Flash is currently not supported due to the fact that it does not implement the .NET framework completely. SmoothMoves requires some .NET structures that are not available in Flash.

    PC, Mac, Android, iOS, and Web are all supported. You can play a web version of "Rise of the Dough" made with SmoothMoves here:

    http://echo17.com/smoothmoves_riseofthedough.html

    Here's a video of an older version of SmoothMoves running on iPad 1:



    You can also download "Rise of the Dough" for FREE on the asset store to test compatibility. You won't be able to modify or create animations, but it should give you a good sense of what is possible:

    http://u3d.as/content/echo17/rise-of-the-dough/3A4

    I use 2D Toolkit and nGUI with SmoothMoves without any problems. You'll need to scale your animations down to get your animations to be on the same scale as 2DTK. See this FAQ here:

    http://www.echo17.com/forum/index.php?topic=247.msg346#msg346
     
    Last edited: Mar 8, 2013
  28. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Check out the latest demo of kontrabida's Rival Theads. It's amazing to see what a good animator can do with SmoothMoves!

    [video=youtube_share;o1HZHu5xSd4]http://youtu.be/o1HZHu5xSd4
     
  29. danthat

    danthat

    Joined:
    Aug 1, 2012
    Posts:
    25
    I'm getting a nasty little error when building. I haven't been able to nail down what's causing it:

    Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.
    UnityEngine.Transform:set_parent(Transform)
    SmoothMoves.AnimationHelper:UpdateBoneAnimation(BoneAnimation)
    SmoothMoves.AnimationHelper:UpdateAnimationDataAndPrefabs(BoneAnimationData, Boolean, Int32, Int32, Int32)
    SmoothMoves.AnimationHelper:UpdateBoneAnimationsAndDataInAllScenes()
    SmoothMoves.ControlPanel:Update()
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

    Um, it's really quite problematic since it can prevent the BoneAnimation being accessed in scripts...
     
  30. Leeyuda

    Leeyuda

    Joined:
    Jan 28, 2013
    Posts:
    4
    Hi,

    I recently bought Smooth Moves to try to do something similar to Zombieville/Battleheart/Mighty Wardens. Since this is my first time creating games in Unity, I'm extremely happy that Smooth Moves seems to have saved me a lot of time in terms of animating my character. However, I am a little stuck on the controller aspect. The controllers that comes with Unity doesn't seem suited for the isometric/cabinet perspective that I'm hoping to achieve.

    Rise of the Dough seems to have the look that I'm looking for and I was wondering if you could help point me in the right direction in terms of what kind of controller scripts or tutorials I should be looking into?

    Thank you so very much for this wonderful tool.
     
  31. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
  32. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Yeah, Unity requires a bit of work when creating a 2D game. I really didn't go off of any tutorials, just created Rise of the Dough from how I thought a 2D game might be structured.

    The essential part of this project is that I used an imaginary 45 degree plane to keep all my characters at the right depth. In essence, I'm just setting the z value of the position of each character to their y position value. This ensures that characters higher up on the screen (higher y value) will be behind other characters.

    $RiseOfTheDough_Perspective.png

    I also used an ortho camera, but if you wanted a bit of parallax like in mikamobile's "OMG Pirates!", you could change this to a perspective camera with a very narrow field of view. Or you could have two cameras, one rendering ortho and another on top of that rendering perspective foreground elements.

    Isometric is extremely tricky in a 3D environment. You could have each 2D element rotated on the x axis 35.264 degrees, the y axis 45 degrees, and offset an arbitrary amount to give it the right depth compared to other elements. You'd then need to rotate the camera 35.264 degrees on the x axis and 45 degrees on the y axis. This will only work as long as you don't have flying elements because the z depth will not be correct. The nice thing about this method is that you can do all your calculations on the x-z plane just like it is the ground, which also means you can use pathfinding like the A* Pathfinding Project.

    Here's some screenshots of buildings using this method. The first screen is what you would see in the game. It looks like the 2D buildings align with their bounding box.

    $Isometric.png

    The second screen is a rotated perspective of the scene view, showing how the 2D elements actually look

    $Isometric_Reality.png

    This screen shows the camera in relation to the scene

    $Isometric_Camera.png

    Again, this method has its flaws. For instance, if you try to fly an airplane behind a tall building, it won't work. You may have to resort to something like Rise of the Dough with the 45 degree plane.

    These are just thoughts so don't get too stuck on them. There are billions of ways to accomplish the same thing in Unity, so it'll probably just take a lot of trial and error! :)

    You're most welcome!
     
    Last edited: Mar 10, 2013
  33. tinoh

    tinoh

    Joined:
    Feb 21, 2013
    Posts:
    28
    Thank you for your thorough response on supported devices/exports. I really like how active you are on this thread and how much time you take for your customers. It makes smooth moves look even better knowing that its developer(s) stand behind it rock solid. Thank you.
     
    Last edited: Mar 11, 2013
  34. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    You're most welcome!
     
  35. Amitloaf

    Amitloaf

    Joined:
    Jan 30, 2012
    Posts:
    97
    I want to create a game with weapons of which the images can be downloaded from the internet. Is there a way to do that? (Obviously i'm asking about the part when you exchange the normal weapon in the animation to a different one.)
    I guess I would need to download either an asset bundle which contains a new pre-made atlas?
     
  36. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Currently that would be a bit tricky. You might be able to accomplish this using the SwapMaterial function. So, just thinking off the top of my head here:

    At design time:
    1) Create a material that will be swapped to. The actual texture used here isn't important.

    At runtime:
    1) Download your texture from your outside server.
    2) Assign the texture to your material you created at design time.
    3) Swap materials in SmoothMoves.

    The downside to this is that you will have to swap an entire material in your animation. This could be costly in draw calls if you wanted each bone to be swapped to a different material. If it is just a single bone with a weapon, that wouldn't be too bad.

    Also, when swapping materials, you have to be sure your atlases' texture line up. So any change you make to your atlas, you will have to make to all atlases.

    I am will be looking into a way to load atlases dynamically so that you can swap individual parts without having to assign every possible atlas in the editor. This could also be used for your scenario in which the actual atlas isn't even available until runtime. This is a future item, so it won't make it into the next release, but it is on my watch list anyway.
     
  37. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I'm going to link to a thread on my forum that has a similar theme to the above question. Hopefully it will give you some ideas...

    http://www.echo17.com/forum/index.php?topic=259.0
     
  38. Amitloaf

    Amitloaf

    Joined:
    Jan 30, 2012
    Posts:
    97
    Thank you! I'll have to try that. Probably will just end up with many images of one weapon instead of atlases because the weapons certainly don't align, it's not just different colors or something but different sizes and shapes.
    I hope I can make this work.

    Anyway, another question. If I want to SwapBoneTexture - why is the original atlas and texture needed? I know the name of the bone I want to assign a new texture to.

    And if i'm at it, a third question. Let's say my character can hold 6 weapons at the same time, all of them are the same. I want to add a shooting animation for the weapons, but I only want to create one such animation and make it so all weapons can use this animation. Can I add an animation sequence to a specific bone or something similar?
     
    Last edited: Mar 13, 2013
  39. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    This is because your bone may go through different atlases and textures throughout a clip. Think of it like sprite animation. If that is the case, you would need to specify what atlas / texture you want to swap out. Obviously this won't be the case every time, but it makes it more flexible.

    I didn't follow the part about all 6 weapons being the same. It sounds like what you are wanting to do is mix animations, where you can play certain bones on top of others. Have a look at this tutorial. It's from v1.x, but the process is the same:

     
  40. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    160
    2D ColliderGen extension for the SmoothMoves framework has just been released
    - Create Precise Polygon Colliders for Entire Scenes at the Click of a Button - Instant 2D Physics -

    First of all, thank you for creating SmoothMoves! It's a fabulous framework, and so many people already benefit enormously from it!

    Please allow me to inform you that we have just released the extension 2D ColliderGen which fully integrates with SmoothMoves.
    The 2D ColliderGen framework allows you to automatically generate precise polygon colliders for your game objects from a sprite image’s alpha-channel. It also works with BoneAnimation characters (check out the video below). The colliders are created within the Unity3D editor in order to have no performance impact at runtime.

    Visit the
    Unity Forum Thread here for more information.

    $screen1_polygon_colliders.jpg

    $screen3_multi_object_editing.jpg

    $screen5_animated_smoothmoves.jpg

    Tutorial Video


    We have chosen to officially support SmoothMoves because we think it's one of the three best 2D extensions for Unity, but that it could get even better with automatic MeshColliders for 2D sprites.

    Hope you like it! :)
    If you have any questions, don't hesitate to ask!
    Thank you!
     
  41. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    Wow! Amazing stuff guys. Many people have asked for this, so I'm sure there will be a lot of happy SmoothMovers :)

    Just downloaded a copy and can't wait to try it out!
     
  42. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    160
    Thank you very much! :)
    Glad to help ;). Hope you like it!
     
  43. Game-Whiz

    Game-Whiz

    Joined:
    Nov 10, 2011
    Posts:
    122
    Not to rain on your parade, but having that many colliders in an already heavy animation system is not a very good idea on mobile.
    Also, using colliders in a character to do collision detection for attacks is not a good idea, since typically these attacks have very fast movement and you take the risk of the collision not being detected (even more if you're upping the physics step time, to enhance game performance). A much safer approach is to do a raycast at the time where the impact would occur (use a trigger to call a method with the raycast).

    Of course, if you're doing a simple game, or plan to run on a PC, you can get away with almost anything :)

    Update: Also, if you decide to go this route (with colliders), be sure to add a RigidBody to your top object, since otherwise PhysX will recompute the collision tree each time a collider moves.
     
    Last edited: Mar 17, 2013
  44. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    160
    @Game Whiz
    Critics are always welcome, thanks for pointing this out! I would also not put mesh colliders on every single character and every limb. But what I would love to see is giant boss fights, where you could climb up on a golem that covers the whole screen to attack his head :). Or sections where you jump from limb to limb / tentacle to tentacle, etc. The demo was just to show what is technically possible.
     
  45. Game-Whiz

    Game-Whiz

    Joined:
    Nov 10, 2011
    Posts:
    122
    Yes, I fully understand that you're trying to show off your brand new product :) I'm just offering some constructive criticism to avoid the pitfalls I fell into. If you have just one boss on the screen, and you're careful with the rest, than it's certainly possible to abuse on the colliders.

    The update above (regarding PhysX) is something you should definitely take into consideration (worth mentioning in the docs). In my case, for the game I'm about to release (http://facebook.com/fangz.game), I had to resort to simple sphere colliders for the enemies and do raycasts. Performance otherwise was not really good. And I had to completely rewrite major parts of SmoothMoves to get it to work in a more complex game (but that's something that would be impossible to describe into one post).

    In my game, for a single scene, I needed to have 600 clips of animation, each with an average of 100 frames and with 20 bones per character average. I also wanted 6 to 8 characters at a time and I wanted it to work between 30 to 60 fps on an iPhone 3gs, together with the rest of the game (AI, particle effects, etc). In the end I was able to achieve this, but all that's left of SmoothMoves in my game is the editor GUI and some other parts... I'm waiting for the SmoothMoves version that integrates with Unity's animation event system to see if things improve and I can use it in future games, but I think that the ease of use that Layne wants to maintain in SmoothMoves will prevent some more advanced features.
     
  46. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    160
    @GameWhiz
    Great game that you have there! Love the cereal part :D.

    Thanks very much for the hint! I have to admit I just wanted to switch the colliders of the original character from box/sphere to mesh colliders, not thinking about anything else. I'll put info boxes on our tutorial video and all docs! Constructive criticism always appreciated!
     
  47. dasbin

    dasbin

    Joined:
    Jan 14, 2012
    Posts:
    261
    Hey echo,

    Do you have an API reference for accessing your Sprite script properties? EDIT: nevermind, found it in your normal API documentation... duh! Thought it wasn't in there for some reason, my bad.
    I'd like to have access to all the sprite properties at runtime, especially the atlas, texture, and color.

    I am also curious what will happen when swapping a Sprite's material during runtime. I really just need to move between two different shaders, either via duplicate atlases AND materials or maybe just duplicate materials referencing the same atlas (is this possible?) And will the sprite continue to reference the same texture, even if the atlas/material has swapped to a duplicate version...l or do I have to re-set the texture every time as well?
     
    Last edited: Mar 18, 2013
  48. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    No problem, glad you found it :)

    Good question. I created a FAQ on my forum located here:

    http://www.echo17.com/forum/index.php?topic=247.msg404#msg404

    After you swap your atlas, you'll need to be sure to reset the texture. You'll need to keep track of the current texture if this won't be changing after the atlas swap. That way you can just swap to that texture after swapping the atlases.

    If you just want to change the shader, then I'd recommend using the material swapping code located in the FAQ link. You can point both materials to the same atlas texture and swap them out.
     
    Last edited: Mar 18, 2013
  49. dasbin

    dasbin

    Joined:
    Jan 14, 2012
    Posts:
    261
    Thank you for the in-detail FAQ!

    Unfortunately I still can't get it to work when trying to preserve the texture (but swap atlas). I'm trying:

    Code (csharp):
    1.  
    2. string idCache = sprite.textureGUID;
    3. sprite.SetAtlas(newAtlas);
    4. sprite.SetTextureGUID(idCache);
    5.  
    But the sprite is not setting the GUID to anything (at least anything valid) and the sprite disappears... even though right now I'm just swapping to the same atlas that is already loaded on the sprite! (So the exact same GUID definitely exists).
     
    Last edited: Mar 18, 2013
  50. echo17

    echo17

    Joined:
    Nov 24, 2011
    Posts:
    1,252
    I added a bit more to the FAQ after my initial post. If all you are interested in is swapping the shaders, take a look at the material swapping section of code at the end of that FAQ. That would probably be a lot easier and you wouldn't have to have duplicate atlases for the same texture.