luxel

  • 2015年8月19日
  • 注册于 2014年11月13日
  • Thank you Mitch & Pharan!
    Glad to know that this is being worked out and looking forward to it.

    btw, how to "bake" the animation to native Unity animations? That sounds new to me. It will be so cool if Spine Editor can somehow output Free-Form Deformation into sprites on the atlas (which can avoid runtime deformation)

  • Hi folks,

    When we're using Spine animation in our unity game (4 characters running at the same time), we found that SkeletonRenderer.LateUpdate is always on the top 3 CPU eater in profiler. And it seems that this component is trying to rebuild the whole mesh every frame. Is there any potential performance improvements that we can make? (by sacrificing some memory, and cache the data of some frequently-used frames, e.g. the frames for "run" animation)

    In our animations we're using Free-Form Deformation, so we have a lot of vertices and triangles. And rebuilding them each frame costs heavy. (we have a lot of spine animations in the scene)

    Please help and let me know your suggestions. The biggest concern here is the performance.

    Thank you!

  • That's cool guys! Looking forward to the binary support :-)

  • Hope we can get binary into Unity soon!!

    The current json parser is making a lot of recursive invocations and allocating a lot of collection objects (thousands of dictionaries), in my personal opinion there is a chance to optimize it.

  • In our skeleton animation for one character, we have a json file with size 190KB. When the whole skeleton animation object is being loaded from asset bundle for the first time, our game pauses for 1 seconds, and there is 4MB memory allocations...It considered slow and too much memory consumption. Is this normal? Or are missing any steps when build the animation files into a bundle?

  • Great, thanks guys! @ProudLittlePinwheel @[已注销]
    My runtime was downloaded from the link providing .unitypackage and never did a pull from github. Now I believe pulling latest source from github will resolve it.

  • Pharan :

    I wish I could help but I don't have a pro license. Does the profiler have the ability to tell which specific things/methods/lines are causing heap allocations?

    Unfortunately no...but it should be showing the allocation is from the main loop of the LateUpdate method.


    After some digging, we found out that this only happens on animation using Free-Form Deformation feature. For animations not using this feature, we're not seeing any heap allocations. One of my wild guess - could it be count of vertices keep changing on Free-Form Deformation animation? (shown as attachments)

    And after I added some "Debug.Log" statements to SkeletonRenderer.LateUpdate method, I found that the allocation is happening here for SkinnedMeshAttachment:

    if (tempVertices.Length < meshVertexCount) {
                      Debug.Log("[SkinnedMeshAttachment] allocatioin temp vertices"); 
                         tempVertices = new float[meshVertexCount];
                      }

    The output of this debug log is also attached.

    Please help with this. I think this should be a common problem for Unity runtime whenever Free-Form Deformation is used.


    Some follow-up...I did some temporary change myself and resolved the memory allocation!

    This is what I did: 😃

    if (tempVertices.Length < meshVertexCount) {
    tempVertices = new float[meshVertexCount];
    // We should remember and reuse the new tempVertices array to avoid future allocation
    this.tempVertices = tempVertices;
    }

    Please help review whether this change will have any side effect.

  • Hi,

    We're developing an online multiplayer racing game, which is quite sensitive on frame rates. But recently we have run into problems where GC takes too much time, so we started some profiling to see our total memory allocations per frame. Surprisingly, we found out that SkeletonRendered.LateUpdate is causing some amount of memory allocations each frame. The total amount of allocations is 2.3 KB for each frame (24 calls).

    Frequent memory allocations could easily lead to unnecessary GC activity. Is there any way to avoid this? All our characters are using Spine animator so we're really looking forward to bring down this.

  • Hi There,

    I have just purchased Spine and starting with my first project with it, using Unity3d tk2d runtime.

    As you know, tk2d sprite collections are using sorting orders to control the orders how the sprites are rendered. However, when my spine skeleton animation is imported into our project, I cannot find where to to set its sorting order. (in tk2d world, it's normally set in tk2dSprite components) As a result, the feet of the character is blocked by the ground objects.

    So how shall I set the tk2d sorting order?

    Thank you!


    After studied the code of tk2d...I managed to add the feature myself!

    In u3d 4.3 and later versions, Renderer object is already supporting the sorting layer. So we just need below:

    Add below properties into SkeletonRenderer:

    Renderer _cachedRenderer = null;
       Renderer CachedRenderer {
          get {
             if (_cachedRenderer == null) {
                _cachedRenderer = renderer;
             }
             return _cachedRenderer;
          }
       }
       
    [SerializeField] protected int renderLayer = 0; /// <summary> /// Gets or sets the sorting order /// The sorting order lets you override draw order for sprites which are at the same z position /// It is similar to offsetting in z - the sprite stays at the original position /// This corresponds to the renderer.sortingOrder property in Unity 4.3 /// </summary> public int SortingOrder { get { return CachedRenderer.sortingOrder; } set { if (CachedRenderer.sortingOrder != value) { renderLayer = value; // for awake CachedRenderer.sortingOrder = value; #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(CachedRenderer); #endif } } }

    In SkeletonRendererInspector class, at the end of gui() method, add below:

    int sortingOrder = EditorGUILayout.IntField("Sorting Order", component.SortingOrder);
          if (sortingOrder != component.SortingOrder) {
             component.SortingOrder = sortingOrder;
          }

    Then we can control the set the sorting order of the animation in editor inspector.

    And in another way, you don't have to do any of the above. Just in the script, directly update the sortingOrder of the renderer object by code...