Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

It was up to us in the command module behind the moon to figure it out

Discussion in 'General Discussion' started by ScottYann, Oct 30, 2014.

  1. ScottYann

    ScottYann

    Joined:
    Jun 14, 2013
    Posts:
    12
    Tell us of your funniest hack. Here's mine to date:

    Mark is working on a electric shock simulator for a company and it involves a character that gets shocked and blasted by a breaker box. They simulate injury wearing ordinary cloths or various levels of PPE (personal protection equiptment). On Monday Mark was given a new model, a man with a t shirt and he needed to bring it into Unity and treat it like the other man models. Sounds easy right? Well 3 days later, here is what we found:

    There is some bizarre difference between the custom .modl format used in the program and FBX imported objects internally inside of Unity. If you swap the mesh of the character with the new t shirt mesh the whole object gets scrambled like an egg. Interestingly the scrambled mesh followed the general outline of the man model. So it was a cylinder of screw up instead of a sphere.

    The new model imports fine however all the old models were imported from a special file format we have no access to. I asked repeatedly for the model exporter but he couldn't find it or didn't know where it is. I said, the company you work for must have it and Mark explained that was 1 or 2 employees ago. The whole project was ported from another project that predates Unity. So to save having to redo a lot of assets, they were translated using Unity's scripting language a long time ago.

    At first I thought, maybe the new mesh lacks the vertex maps for mesh deformation controls (weight maps in Lightwave) and all the bones had the same influence. But it turned out it did have all the right vertex maps.

    Then I thought maybe there is an import setting somewhere that has the solution. But I tried every possible combination.

    It would be a simple matter of just applying the animations to the bones right? Apparently not. I could not find any way of getting it to animate. Animations would not preview at all so apparently this option for us was closed.

    I also thought of exporting the old model, tweaking it and bringing it back in. Silly rabbit, that trick won't work because the handy export script from Unity, doesn't work with the bizarre .modl format. Besides, how could that work, Scott, you already showed that re importing it would ruin it just as if it came from any other program. Yeah we tried a lot of things.

    We were sure it was because of the mesh import because when we replaced the body mesh with the new t shirt mesh, yes it was scrambled, but all the other meshes from .modl prefabs worked without getting scrambled. They even followed the animation.

    Nobody anywhere online has this problem. It was up to us in the command module behind the moon to figure it out.

    By Wednesday we were no closer. Then while we were moving one of the bones to make sure it was deforming a mesh at all with its own built in skeleton from the import I had an idea. Why not just force the transforms of the old bones upon the new bones? We did the first arm and it apparently worked. Mark liked this idea so he got to work at about 3 pm. At 4 pm Mark said it was going to work.... but not without a fight. So I stopped on over for a visit.

    We made a script called possessor transmitter to control the new t shirt skeleton and mesh. We were going to make this great and elegant script to automatically find the right skeleton object and transmit skeleton transforms to it. But after about half an hour messing with it I said lets mow this lawn and in about an hour later we got it all done by manually setting the public variables. After this some funny things started happening.

    When the program was run the legs moved perfectly. But the arms were spazzing out in hilarious ways. It was the ultimate glitch fest. At some points it reminded me of the Thing.

    I thought it could be the references were wrong but that wasn't it. I thought it could be a couple missing bones and that wasn't it. One of the hacks we did was rotate the transform of all the bones to make it align generally. All this time getting more and more hilarious glitches. At one point the mans face was poking out of his back. Another time his arms swayed through his body. Perfect for Halloween, a possession script making a man spazz out.

    The behavior was that the individual transforms for the bones in the arms were wildly vibrating. But the legs and most of the body was ok.

    It looked bleak. Then it occurred to me, the bones are all about the same length and same position. There is no reason at all we couldn't just change their parent structure to parent up to the old skeleton. THAT WORKED! And it was all better. It was a decisive victory. Yay! I should have done this from the beginning. But I hadn't worked in Unity for about a year so I didn't see how bad the transform application idea was.

    What other options did we have? We'll I guess we could have reverse engineered the importer and make our own exporter. That would require mastery of 2 file formats, and one of them is not documented anywhere on this planet. Or analyze the importer script to see how it mangles the data. Pouring over the rest of the code would not yield many answers because this is not just a runtime problem, it also applies when the program is not running.

    Another option we had was finding all the original models and animations and reimport them as fbx, obj, dae or whatever they were. But that would have involved bugging Mark's employer and besides, they might not even have those objects anymore! Same issue with finding the original animations, we could get it to animate this way if we had them. But we didn't.

    Maybe the solution was really just figuring out why the animations didn't play. But I didn't know if not only the model data was a bizarre custom thing just like the mesh data. I figured it was.

    Maybe the answer was just a mesh property that normally is not controlled in a property inspector with the special custom .modl format. It could be that simple maybe. But we searched for this problem on Google and I never saw anyone having it or mentioning a special bastard property no one uses.

    So there you have it, we exorcised a bug in Unity by voodoo possession. In time for Halloween!
     
  2. randomperson42

    randomperson42

    Joined:
    Jun 29, 2013
    Posts:
    974
    If only you had a GIF. :)