Jump to content

SpriterDotNet.Unity


loodakrawa

Recommended Posts

4 minutes ago, loodakrawa said:

The generation toggle sounds like a good idea. I'll implement it along with the other thing. Just as a heads up, it probably won't happen any time soon since I don't use Unity as the game dev platform of choice anymore.

No worries.  If you don't mind me asking, what is your development environment of choice (assuming you're still using Spriter with it)?

What I'm planning on trying to do is essentially implement my own clone of Don't Starve Together.  So won't really use a ton of Unity's features anyways.

Link to comment
Share on other sites

It's been a while since I fiddled with anything Spriter or Unity, but either way, the process for creating a prefab from a script is basically.

1) Create an empty GameObject
2) Instantiate supporting objects (like the data container ScriptableObject that SDN.Unity uses)
3) Add Components to the GameObject
4) Set the values in said Components
5) Save the GameObject as a prefab
6) Save supporting objects as assets
7) Delete the GameObject

Steps 5 and 6 are possible at Editor Time only, and I'm fairly sure steps 1 through 4 don't even need any Editor code. You would need a different "Step 0" (acquiring and reading the .scml file) though.

Regardless, creating a spriter object at runtime would skip steps 5 through 7.

A word of caution though, from my understanding, there would be two possible problems, and solving one could possibly cause the other. Although there's probably fixes for these, I can't think of any right now.

Basically, the first issue is that reading the .scml file and creating the GameObject takes a while. Depending on the size of the .scml and the amount of .scmls you are trying to read, this might not be a huge issue.

The second issue has to do with the fact that the resulting GameObject can't be saved as a prefab at runtime, since this requires Editor code. The only way to retain easy access to the spriter object is to keep it in memory the entire time. Depending on how often the spriter object is used in your game, this might not be a huge issue.

The first problem can be solved by only reading the .scml file once and keeping the GameObject in memory.
The second problem can be solved by destroying the GameObject when you no longer need it and rebuild it from the .scml when you need it again.

So... yes, the solution to one problem causes the other. That being said, depending on how your game works, one of these problems might not be a huge issue.

 

Of course there might be something I'm missing here and there's not really that much of an issue. If you want to speed up the read process, you could alternately import the .scml data once, then save that data to a faster medium, such as MessagePack. It's sad that Unity doesn't let you use its own native serialization system at runtime, that would be ideal.

Oh and there's also the issue of using external image files. I mean it's quite possible, but the code for reading them is different (and possibly slower?) at Runtime than it is at Editor Time.

Link to comment
Share on other sites

@Dengarthanks for that information.  It has been quite awhile since I've personally developed in Unity as well.

I am quite curious if you know whether or not having a large amount of prefabs would also suffer from these two issues you bring up (if you know)?  If there is a huge benefit regarding prefabs over direct loading (and keeping in memory), perhaps I should just go the route of using asset bundles for additional content.  Since Unity is free, it wouldn't really force users to pay to mod for the engine and would just add an extra step.

Link to comment
Share on other sites

16 hours ago, Ecu said:

No worries.  If you don't mind me asking, what is your development environment of choice (assuming you're still using Spriter with it)?

What I'm planning on trying to do is essentially implement my own clone of Don't Starve Together.  So won't really use a ton of Unity's features anyways.

I'm using MonoGame and I've been really happy with it. I takes a bit of extra work initially but I think it pays off in the long run because it is just a good tool that doesn't force you to do things a certain way (+ it is open source).

As the IDE, I'm using Visual Studio Community which comes with integrated Xamarin.

And of course, the SpriterDotNet MonoGame variant for all my Spriter animation needs.

As for Unity, I'm still using it but only as a level editor and I find it absolutely fantastic in that role.

About the (really good) points @Dengar made:
The loading impact can be mitigated if it's done during (or just after) the scene load and not in the middle of running the game. As for the memory - I'm fairly certain that dynamically loaded things have the same memory footprint as the ones instantiated from prefabs, at least while you only have one instance. With multiple instances prefabs work as a Flyweight Pattern which is something you want to do with dynamically loaded ones as well. In a similar fashion, SpriterDotNet uses ScriptableObjects to share common data between different Entities from the same Spriter file.

Hope that helps :)

Link to comment
Share on other sites

6 minutes ago, loodakrawa said:

I'm using MonoGame and I've been really happy with it. I takes a bit of extra work initially but I think it pays off in the long run because it is just a good tool that doesn't force you to do things a certain way (+ it is open source).

As the IDE, I'm using Visual Studio Community which comes with integrated Xamarin.

And of course, the SpriterDotNet MonoGame variant for all my Spriter animation needs.

As for Unity, I'm still using it but only as a level editor and I find it absolutely fantastic in that role.

About the (really good) points @Dengar made:
The loading impact can be mitigated if it's done during (or just after) the scene load and not in the middle of running the game. As for the memory - I'm fairly certain that dynamically loaded things have the same memory footprint as the ones instantiated from prefabs, at least while you only have one instance. With multiple instances prefabs work as a Flyweight Pattern which is something you want to do with dynamically loaded ones as well. In a similar fashion, SpriterDotNet uses ScriptableObjects to share common data between different Entities from the same Spriter file.

Hope that helps :)

That does help quite a bit.  I'll consider checking out MonoGame and see if I might want to use that instead.  Appreciate all the information.

Link to comment
Share on other sites

The main advantage of using an actual prefab (which can't be constructed at runtime) is the fact that prefabs are serialized using Unity's native serialization system. All Unity assets are deserialized at the actual engine layer (where the engine does its job) rather than the scripting layer (where all of our scripts are run). It stands to reason that Unity's deserializer is more optimized than anything we can come up with on the scripting layer. Instantiating a preconstructed prefab will most definitely be significantly faster than first creating a GameObject from scratch, add components to it, and then populate the components' fields with values read from an XML file.

MonoGame is a programmer's paradise, really. It gives you absolute control over absolutely everything. The downside? It's not a game engine at all. You will have to write all the rendering and physics code yourself (or borrow it from an open source), and there is no editor at all, let alone a fancy one like Unity. That said, I much prefer it over Unity for 2D games since Unity does many unnecessary things that you can't really turn off. And SpriterDotNet also works with it.

 

@loodakrawa You use Unity as a level editor? What do you do then? Write the assets to disk as text and then import those into your MonoGame project using a custom importer?

Link to comment
Share on other sites

10 hours ago, Dengar said:

The main advantage of using an actual prefab (which can't be constructed at runtime) is the fact that prefabs are serialized using Unity's native serialization system. All Unity assets are deserialized at the actual engine layer (where the engine does its job) rather than the scripting layer (where all of our scripts are run). It stands to reason that Unity's deserializer is more optimized than anything we can come up with on the scripting layer. Instantiating a preconstructed prefab will most definitely be significantly faster than first creating a GameObject from scratch, add components to it, and then populate the components' fields with values read from an XML file.

MonoGame is a programmer's paradise, really. It gives you absolute control over absolutely everything. The downside? It's not a game engine at all. You will have to write all the rendering and physics code yourself (or borrow it from an open source), and there is no editor at all, let alone a fancy one like Unity. That said, I much prefer it over Unity for 2D games since Unity does many unnecessary things that you can't really turn off. And SpriterDotNet also works with it.

 

@loodakrawa You use Unity as a level editor? What do you do then? Write the assets to disk as text and then import those into your MonoGame project using a custom importer?

Hrm.  I might stick with Unity and go with the prefab method (at least for now).  MonoGame sounds great, but I am not too keen on establishing my own physics engine, my own 3D rendering, etc.  While I indeed plan on using Spriter for my project, the goal is to have an engine like this (Don't Starve Together).  

It actually uses Spriter for it's animations as well, only in a 3D world.  The terrain is a flat quad that renders via tiles, all entities are 2D Spriter models, and there is a form of physics for items.  In addition, it utilizes Lua for content scripting.  I really feel an engine like this has a ton of promise, however, rather than modding it...I'd like to create my own rendition.  On reason is because some things have been hardcoded into the core engine and not exposed to scripting.  Another is purely the challenge of getting such an engine working.

So Unity might work best for me.  I know I could definitely achieve all of these goals via MonoGame, however, I'm a designer more than I am a developer.  I enjoy the art and system design far more than I do implementing said engine.  As such I feel like trying to learn how to get all these working in MonoGame may cause me to give up from frustration if I cannot achieve my aims at a reasonable pace.

I'll look into MonoGame a bit though, maybe it is easier than I am expecting.  If you happen to have some specifics I should look into, please share them.

 

Link to comment
Share on other sites

When I said "programmer's paradise" it means literally a paradise for a programmer. Someone who focuses more on visuals or designing the game itself might not find it very appealing. That said, if you want to improve your programming skills and learn to program a game at its base level, I can't think of a better framework tbh.

Link to comment
Share on other sites

On 02/12/2016 at 8:35 PM, Dengar said:

@loodakrawa You use Unity as a level editor? What do you do then? Write the assets to disk as text and then import those into your MonoGame project using a custom importer?

I export the scenes in a json format with a bunch of properties for every object (like transforms sounds, layers, etc...) and read that in MonoGame. As for the assets, I just save the paths to sprites/sounds and have the same assets structure in both the Unity editor and MonoGame runtime. Nothing too complicated but works really well.

 

On 03/12/2016 at 7:00 AM, Ecu said:

Hrm.  I might stick with Unity and go with the prefab method (at least for now).  MonoGame sounds great, but I am not too keen on establishing my own physics engine, my own 3D rendering, etc.  While I indeed plan on using Spriter for my project, the goal is to have an engine like this (Don't Starve Together).  

It actually uses Spriter for it's animations as well, only in a 3D world.  The terrain is a flat quad that renders via tiles, all entities are 2D Spriter models, and there is a form of physics for items.  In addition, it utilizes Lua for content scripting.  I really feel an engine like this has a ton of promise, however, rather than modding it...I'd like to create my own rendition.  On reason is because some things have been hardcoded into the core engine and not exposed to scripting.  Another is purely the challenge of getting such an engine working.

So Unity might work best for me.  I know I could definitely achieve all of these goals via MonoGame, however, I'm a designer more than I am a developer.  I enjoy the art and system design far more than I do implementing said engine.  As such I feel like trying to learn how to get all these working in MonoGame may cause me to give up from frustration if I cannot achieve my aims at a reasonable pace.

I'll look into MonoGame a bit though, maybe it is easier than I am expecting.  If you happen to have some specifics I should look into, please share them.

 

 

 

5 hours ago, Dengar said:

When I said "programmer's paradise" it means literally a paradise for a programmer. Someone who focuses more on visuals or designing the game itself might not find it very appealing. That said, if you want to improve your programming skills and learn to program a game at its base level, I can't think of a better framework tbh.

I absolutely agree. MonoGame is "just" a framework for multi-platform DirectX/OpenGL rendering which it does really well. That means you have to tell it what to draw and where. That also means that you have to implement / integrate 3rd party tools for physics, entity component systems, scene graph, etc. Which is something I really like because I fell like I have total control of what's going on in the game I'm making.

I actually started with Unity since everyone was saying it's basically promised land for anyone making indie games. After 6 months of work I switched to MonoGame and didn't look back. However, I'm a hardcore developer and I understand it might not be for everyone.

@Ecu My suggestion is to try both and see what works for you.

Link to comment
Share on other sites

3 hours ago, loodakrawa said:

I export the scenes in a json format with a bunch of properties for every object (like transforms sounds, layers, etc...) and read that in MonoGame. As for the assets, I just save the paths to sprites/sounds and have the same assets structure in both the Unity editor and MonoGame runtime. Nothing too complicated but works really well.

 

I absolutely agree. MonoGame is "just" a framework for multi-platform DirectX/OpenGL rendering which it does really well. That means you have to tell it what to draw and where. That also means that you have to implement / integrate 3rd party tools for physics, entity component systems, scene graph, etc. Which is something I really like because I fell like I have total control of what's going on in the game I'm making.

I actually started with Unity since everyone was saying it's basically promised land for anyone making indie games. After 6 months of work I switched to MonoGame and didn't look back. However, I'm a hardcore developer and I understand it might not be for everyone.

@Ecu My suggestion is to try both and see what works for you.

Thanks for the additional information.  It does sound like Unity (at least to begin with) would definitely better suit me as it would let me leverage existing systems without much work.

Regarding direct loading vs. prefab loading, I will probably stick with the prefab method for now.  I would like to ask, is there a good method for me to leverage one prefab for animations and apply said animations to others via this toolkit?  Since it is likely I'll utilize multiple swappable parts (clothing, heads, etc.) that are shared between characters, it would be more efficient to have one main file that is animated and then using said animations for the others.  Is this feasible, or will I have to just use the same rig for each new part and have the animations stored in each prefab separately?

Link to comment
Share on other sites

20 hours ago, Ecu said:

Thanks for the additional information.  It does sound like Unity (at least to begin with) would definitely better suit me as it would let me leverage existing systems without much work.

Regarding direct loading vs. prefab loading, I will probably stick with the prefab method for now.  I would like to ask, is there a good method for me to leverage one prefab for animations and apply said animations to others via this toolkit?  Since it is likely I'll utilize multiple swappable parts (clothing, heads, etc.) that are shared between characters, it would be more efficient to have one main file that is animated and then using said animations for the others.  Is this feasible, or will I have to just use the same rig for each new part and have the animations stored in each prefab separately?

I think character maps solve most of the things you mention here and they're already supported in SpriterDotNet.

Link to comment
Share on other sites

1 hour ago, loodakrawa said:

I think character maps solve most of the things you mention here and they're already supported in SpriterDotNet.

That would indeed work for a game where all assets are meant to be under my control.  However, I'm not quite sure that would work quite well for a game where users can contribute content.  My current plan was to have each part separately animated, and then assembling the character out of these parts when chosen, using a control game object to handle triggering animations and such.

Link to comment
Share on other sites

  • 2 months later...

Hello,

First, I'd like to say thank you for this awesome library!

I am creating characters with the RPG Heroes art pack. What I would like to do is have an equipment-less and clothes-less character prefab with full paperdolling and customization support. I would like to dynamically layer the equipment and clothes onto the character while also respecting their origin points during animation. I would also like to dynamically swap out certain textures, such as the skin tones, eyes, ears, hair, ect, while also respecting the origin points during animation.

I read this entire topic to find some info on my problem, and it seems like a few people had the same question, but I wasn't able to figure out a proper solution from the discussions. If you watch the trailer on the RPG Heroes pack @ 1:10, you will notice that it show's support for dynamically changing animations and "changing wardrobe pieces on the fly", with Construct 2 engine. How would I go about that with this Library?

I am new to Spriter, but I think the best course of action is to not re-invent what Spriter already supports, and just dynamically add and remove active character maps that are currently in the "scml" file.

Also, is there support for dynamically changing the color palettes?

Thank you for your time!

 

Link to comment
Share on other sites

Excuse me!
I'm using SpriterPro with Unity 5.5

I don't know if this has been asked before:

is there anyways to change a sprite at run-time?

I have model A, and part "7 arm", I animated this model with the said part.
at some point in run-time, I want to change the part "7 arm" to "7 arm_B" (just a re-color), but changing the sprite of SpriteRenderer has no effects

spriter.thumb.png.6b556f5bc06e2d8ddbd94170c4f05960.png

Thank you for your time!

On 2/18/2017 at 6:34 AM, Shilo86 said:

I read this entire topic to find some info on my problem, and it seems like a few people had the same question, but I wasn't able to figure out a proper solution from the discussions. If you watch the trailer on the RPG Heroes pack @ 1:10, you will notice that it show's support for dynamically changing animations and "changing wardrobe pieces on the fly", with Construct 2 engine. How would I go about that with this Library?

 

I think my need is similar to this.

Link to comment
Share on other sites

The feature in Spriter is called "Character Maps". I'm pretty sure SpriterDotNet for Unity does support that feature. Perhaps if you search through its doccumentatino or examples for the words "character map" pr "charmap"

13 hours ago, TomKazansky said:

Excuse me!
I'm using SpriterPro with Unity 5.5

I don't know if this has been asked before:

is there anyways to change a sprite at run-time?

I have model A, and part "7 arm", I animated this model with the said part.
at some point in run-time, I want to change the part "7 arm" to "7 arm_B" (just a re-color), but changing the sprite of SpriteRenderer has no effects

spriter.thumb.png.6b556f5bc06e2d8ddbd94170c4f05960.png

Thank you for your time!

I think my need is similar to this.

 

Link to comment
Share on other sites

On 18/02/2017 at 10:34 AM, Shilo86 said:

...

 

On 19/02/2017 at 3:23 PM, TomKazansky said:

...

 

Hey guys,

To change sprites during runtime, either use Character Maps or swap sprites directly (for a more granular control). Both functionalities are achieved via the various IAssetProvider's methods (PushCharMap and PopCharMap for char maps and Swap and Unswap for individual sprites). Take a look at the Controller in the example project to see how it's done.

Link to comment
Share on other sites

  • 4 months later...
6 hours ago, Farbfinsternis said:

This package doesn't work with Unity 2017.

It was bound to happen. I put the development of the Unity version on hold at least until they decide to support a more modern .NET version. I think this means waiting for .NET Standard 2.0 since they said they will support it once it comes out. Unity 2017.1.0 seems to be on the right track with the (experimental) support for C# 6 and .NET 4.6.

Link to comment
Share on other sites

1 hour ago, Farbfinsternis said:

Ok, in this case Spriter is useless for me. Thanks for the fish.

It's less feature-rich, but you could possibly use Spriter2Unity to convert Spriter made animations into native Unity animations, so long as you make sure not to use the few features Spriter2Unity can't support.

Or, perhaps you could develop with the older version of Unity?

Link to comment
Share on other sites

Damn... I just bought Spriter for a major client project, assuming this would work in Unity 2017.1

Just tried it out and it *seemed* to work, until I used the controller to switch animations, most of which worked, but some just did some weird skewed scaling thing. FYI, I tried it on the female character from the Run n' Gun Platformer pack.

If you can take a look at updating / fixing the issues, that'd be most welcome! (pretty please!)... Otherwise, it's been a bit of a deal breaker for me...

Off to try the other Spriter2UnityDX plugin in the meantime...

Link to comment
Share on other sites

12 minutes ago, tnaseem said:

Damn... I just bought Spriter for a major client project, assuming this would work in Unity 2017.1

Just tried it out and it *seemed* to work, until I used the controller to switch animations, most of which worked, but some just did some weird skewed scaling thing. FYI, I tried it on the female character from the Run n' Gun Platformer pack.

If you can take a look at updating / fixing the issues, that'd be most welcome! (pretty please!)... Otherwise, it's been a bit of a deal breaker for me...

Off to try the other Spriter2UnityDX plugin in the meantime...

Hi,

If there are glitches or issues with transforms I'll definitely investigate since the core problem might be a bug in the core library. There's a big difference between "It doesn't work" and "there are glitches" ;-)

Can you please post as much info as possible about the issue so I can look into it?

Link to comment
Share on other sites

Many thanks. :) 

It's definitely working (of sorts)... so, I'll go through the steps below... (typing this as I do them):

This is in Unity 2017.1.0f3 on MacOS 10.12.6 (Not tried it on my WIndows dev kit yet...)

  1. Imported SpriterDotNet.Unity.Examples.unitypackage into Unity (FYI. See ImportLog.txt for Warnings in the Unity console).
  2. Drag example Controller into empty scene.
  3. Drag Female_Player project folder from the Run n' Gun Pack into the Unity assets folder.
  4. Prefabs for 3 Female anims created fine - (Player_arm_cannon, Player_gun, Player_sword).
  5. Drag Player_gun prefab into scene (Looks good).
  6. Run the game in the Editor. Idle animations run perfectly.
  7. SwitchAnimation() works fine. All animations can be switched to.
  8. Problems with Transition(): First 3 transitions work fine (hitting right arrow - Transition(1)). 4th transition does a weird scale and rotate of the helmet. Happens with a couple of the other transitions too, but not all.

    WarmComplicatedBoto-size_restricted.gif
     
  9. PushCharacterMap() goes through the maps but ends up with a headless character (Red Herring: See my EDIT below!)

    LoathsomeSickCarpenterant-size_restricte

Now, I'm new to Spriter, and SpriterDotNet, so no idea if any of these are expected behaviours (something with the animation project itself!?), but this is what I've noticed so far with the very little I've had a play with. Not had a chance to go through the controller code yet either, other than looking at the key presses! Anyway, I hope this helps.

EDIT (26/07/2017):
Forget the headless thing. I've just been playing with the CharMap in Spriter for this character and there is indeed a headless version in there! Sorry for the confusion. However, I've left the gif up so you can see the rotations going wrong.

 

Cheers,
Tarique
 

 

 

 

 

 

 

ImportLog.txt

Link to comment
Share on other sites

On 7/25/2017 at 9:01 PM, tnaseem said:
  1. Problems with Transition(): First 3 transitions work fine (hitting right arrow - Transition(1)). 4th transition does a weird scale and rotate of the helmet. Happens with a couple of the other transitions too, but not all.

    WarmComplicatedBoto-size_restricted.gif

 

I've investigated and this issue is happening due to the fact the animations don't have an identical layout (which is a requirement for animation blending to look right). For example, this is causing the head from animation 1 to be blended with something else (like an arm) from animation 2 which obviously results in weird things happening.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...