Giter VIP home page Giter VIP logo

Comments (13)

NathanSweet avatar NathanSweet commented on May 22, 2024

How do you reproduce this? Seems to work fine if I change the SpineboyComponent to:

    public void OnMouseDown () {
        SkeletonAnimation skeletonAnimation = GetComponent<SkeletonAnimation>();
        skeletonAnimation.enabled = !skeletonAnimation.enabled; // <- added this
        skeletonAnimation.state.SetAnimation("jump", false);
        skeletonAnimation.state.AddAnimation("walk", true);
    }

from spine-runtimes.

pharan avatar pharan commented on May 22, 2024

Did some more snooping.
I added these lines right before the colors and uvs get submitted to the mesh:

        if(vertices == null)
            Debug.Log ("vertices was null");
        if(vertices.Length != colors.Length)
            Debug.Log (vertices.Length.ToString() + " " + colors.Length.ToString());

and... for some reason, I get this:

NullReferenceException: Object reference not set to an instance of an object
SkeletonComponent.Update () (at Assets/Plugins/Spine/SkeletonComponent.cs:166)

line 166 is the first if-check.
I also get the error at 168.

Could it have something to do with the fact that my skeleton has a setup pose that has all its slots set to have no image/attachments?

from spine-runtimes.

NathanSweet avatar NathanSweet commented on May 22, 2024

Hard to say. Set a breakpoint?

from spine-runtimes.

pharan avatar pharan commented on May 22, 2024

found the prob. Not sure what the best solution is:

        // Count quads.
        int quadCount = 0;
        List<Slot> drawOrder = skeleton.DrawOrder;
        for (int i = 0, n = drawOrder.Count; i < n; i++) {
            Slot slot = drawOrder[i];
            Attachment attachment = slot.Attachment;
            if (attachment is RegionAttachment)
                quadCount++;
        }

        // Ensure mesh data is the right size.
        Vector3[] vertices = this.vertices;
        bool newTriangles = quadCount > vertices.Length / 4;
        if (newTriangles) {
            this.vertices = vertices = new Vector3[quadCount * 4];
            colors = new Color[quadCount * 4];
            uvs = new Vector2[quadCount * 4];
            triangles = new int[quadCount * 6];
            mesh.Clear();

If none of the slots had an image attachment when it begins, quadCount stays 0.
And if it's 0, newTriangles evaluates to false;
therefore, colors, uvs and vertices never get allocated for and assigned.

from spine-runtimes.

pharan avatar pharan commented on May 22, 2024

just off the top of my head

if (quadCount == 0) return;

? xD

from spine-runtimes.

NathanSweet avatar NathanSweet commented on May 22, 2024

Yea that sounds good.

from spine-runtimes.

pharan avatar pharan commented on May 22, 2024

actually, it might be

if(quadCount == 0) {
    mesh.Clear();
    return;
}

I'll have to test this thoroughly to see if it works well in other cases.

from spine-runtimes.

pharan avatar pharan commented on May 22, 2024
    public virtual void OnDisable () {
        if (Application.isEditor)
            Clear();
    }

The OnDisable code seems to cause it to behave differently when testing the game in Unity and when testing the game as a standalone.

More weird things started to happen (which gets fixed when I comment this out).
I'll have to look into this further.

from spine-runtimes.

NathanSweet avatar NathanSweet commented on May 22, 2024

Any updates on the weirdness? :)

from spine-runtimes.

pharan avatar pharan commented on May 22, 2024

Haven't been able to get a hold of hippocoder.

Anyway, turns out

if(quadCount == 0) {
    mesh.Clear();
    return;
}

is kind of unnecessary if I just make sure the stuff that were instantiated in Initialize() don't get obliterated by Clear() with OnDisable() either while testing the game or in an actual build.

I kinda get the logic behind clearing these things in the editor while editing, but the current code unfortunately has the effect of also making SkeletonComponents go crazy while testing the game in the editor under those conditions: imageless setup pose + enabling and disabling Unity GameObjects as part of game logicβ€” a common setup for me for effects animations.

What I just did was just comment out OnDisable() and it works fine. Pretty sure that removes something useful you were trying to do with it in the first place though, so I'm not sure what to recommend.

from spine-runtimes.

NathanSweet avatar NathanSweet commented on May 22, 2024

TBH, I don't really remember WTH I was doing. Unity's lifecycle stuff isn't super clear. Probably it is there to reset the state when things change in the editor...

from spine-runtimes.

NathanSweet avatar NathanSweet commented on May 22, 2024

I guess we'll close this one for now. Can always reopen if needed.

from spine-runtimes.

pharan avatar pharan commented on May 22, 2024

Just for the record.

#if UNITY_EDITOR
   public virtual void OnDisable () {
         Clear();
   }
#endif

This still caused the same problem. Commenting it out still fixes it.

from spine-runtimes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.