Announcement

Collapse
No announcement yet.

Spawning a object during animation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Spawning a object during animation

    As stated in the title of this topic, I was wondering how does one go about spawning a object when a animation is playing?

    You see I'm trying to make a attack animation for my player character where the character reaches behind their back and pulls out a weapon à la Looney Toons. The character then swings their weapon and then puts the weapon back behind their back where the weapon then disappears.

    I've created the necessary animation and have mapped to the animation blueprint, so everything is in place except for the missing weapon.

    I was also wondering about rotating a object during animation as well. The reason for this is because as part of the act of swinging the weapon in a downward motion, it is necessary for the swinger to turn their wrists downwards, which is a problem because my character doesn't have any hands. Instead my character has sausage-like limbs, necessitating the weapon to rotate its position in order to simulate a person turning their wrists downwards. Without the simulation of turning one's wrists during a swing, my character would have a non-existent attack range due to his rather short arms, causing a variety of gameplay issues.

    Any help whatsoever would be greatly appreciated!

    #2
    You want to call SpawnActor to get your weapon into the game. Then you attach the weapon to your mesh via a socket. When you are done simply detach and call Destory on the weapon actor.
    UE4 Tutorials for 3rd person Blueprint project from scratch: Youtube Channel
    Use Blender 2.8 to make UE4 compatible animations: Blog

    Comment


      #3
      You can also add a curve (either standalone or to the animation itself) to represent the amount of rotation your weapon should have. Then during animation play you can update the weapon transform based on the the curve values.
      UE4 Tutorials for 3rd person Blueprint project from scratch: Youtube Channel
      Use Blender 2.8 to make UE4 compatible animations: Blog

      Comment


        #4
        Ok now I feel like I'm spamming but last response for sure this time. It occurs to me you don't need a mesh for an armature to work correctly. The easiest way to do this would be to simply author your animations with a hand/weapon bone. You don't need to have a hand mesh to go along with it. This way you'd get the most accurate animation control for your character.
        UE4 Tutorials for 3rd person Blueprint project from scratch: Youtube Channel
        Use Blender 2.8 to make UE4 compatible animations: Blog

        Comment


          #5
          I was going to suggest just that.
          depending on the weapon of course. If it's just a mallet and has no player controls a one shot animation works best.

          if you need to pull out a gun and need to trigger it things get more complicated.
          if you want the mallet to "find" the enemy things get more complicated too...

          If you wanted to go the crazy way about it you could create a morph target weapon, flatten out its geometry so it's essentially invisible and inflate it during animation time with a morph target...
          You did say LOONEY Toons...

          Comment


            #6
            Ok now I feel like I'm spamming but last response for sure this time. It occurs to me you don't need a mesh for an armature to work correctly. The easiest way to do this would be to simply author your animations with a hand/weapon bone. You don't need to have a hand mesh to go along with it. This way you'd get the most accurate animation control for your character.
            Thanks for this suggestion, adding a "grip" bone has greatly simplified things. If I had tried to animate the movement of my character's weapon otherwise, it almost certainly would have turned into a overly complicated nightmare. I also had to modified the swinging animation a bit due to the fact that I originally made the animation without the required weapon in hand and so attaching it to the newly created "grip" bone exposed that the weapon would end up clipping through my character.

            Unfortunately though, fixing that one problem has created a new one in its place that is now currently vexing me. After creating a socket on the new "grip" bone I tried to include a Add Preview Asset so that I would be able to see the weapon on my character while trying to figure out the blueprint for the Animation Notifies to spawn/despawn the weapon in the animation. However, instead of the weapon appearing in my character's "hand", the weapon instead appeared in the middle of the character model. I then tried to move the weapon asset over to the where the "grip" bone was, but for some reason I could not move the weapon, I could alter its scaling & rotate it but I could not move the object from its default position.

            While trying to figure out why I couldn't move the weapon object to its proper location, I noticed that in the bone hierarchy displayed on the left side on the screen that "grip" bone appeared grayed out along with a bunch of bones that were based modifiers from Blender that were incompatible with Unreal Engine 4. Highlighting the grayed out bones would display the following message:

            The Bone exists only on the skeleton but not on the current mesh
            I tried doing a Google Search for this message and came across this topic:

            https://forums.unrealengine.com/deve...e-current-mesh

            I'm fairly certain the problem scenario described in the above topic is the same one that I am currently with, but I have no idea how to fix this issue. I tried re-importing my character model from Blender without any of the bones that used modifiers from Blender that were incompatible with Unreal Engine 4. I also made some changes to all of the animations I've made to date by highlighting all of the bones within the armature minus the aforementioned incompatible "modifier" bones and choosing to export only the bones I had highlighted.

            Alas though, despite all of the my efforts of re-importing the mesh/armature and all of its animations, the problem continues to persist just as it did before I made all of my alterations.

            Does anyone have any idea on how I can rectify this new problem?

            EDIT: I thought I should also mention that despite deleting the "modifier" bones from my model and not including them in the animation armatures when I exported them as a .FBX file, the bones are still present in my model's armature in Unreal Engine 4. I'm not sure whether or not this is directly related to why the "grip" bones aren't being properly registered by Unreal but I thought I should mention just in case.
            Last edited by Hungry Moogle; 07-16-2019, 12:42 AM.

            Comment


              #7
              I don't know what you are doing exactly but I can tell you this:
              In blender when you delete things from an armor and it still imports the same things in the armor the more likely reason is that you may have removed the items on the Pose and not in Edit Mode.
              Editmode deletions propagate to pose mode. Vieceversa they do not.
              Your animation is likely Baked (that's usually how blender imports from an FBX, 1 key every frame). Before exporting you need to NLA Bake the action with visual and whatever other options within the panel you think appropriate - Then the files can be re-imported and the armature changes will take place without issue.

              For putting the weapon in hand and animating - depending on actual needs (since your need is to spawn via BP you'll have to work the BP ) - you can try following the sequencer tutorial.
              https://youtu.be/e4fr23pVEuo?t=172

              Comment


                #8
                I don't know what you are doing exactly but I can tell you this:
                In blender when you delete things from an armor and it still imports the same things in the armor the more likely reason is that you may have removed the items on the Pose and not in Edit Mode.
                Editmode deletions propagate to pose mode. Vieceversa they do not.
                It's not in Blender where the deleted bones are reappearing but Unreal Engine. The only reason I can think of why this happening is because the main character model & all of its animations are being imported into Unreal Engine from two different Blend files. The Blend file with the main model is the one that I deleted the "modifier" bones from, while the other one containing all of my character's animation maintained those bones because I needed the Inverse Kinematics bone restraint to animate my character. Instead, I tried selecting all necessary bones while leaving out the "modifier" bones that were not compatible with Unreal Engine & turned on Selected Objects in the Export FBX options. I guess its possible that the Selected Objects option didn't work as I intended and instead imported the entire armature rather than just the bones I selected.

                However, while I would prefer to get rid of the incompatible bones that serve no purpose in Unreal Engine, none of this explains why the "grip" bones I added to my model for the purpose of attaching the weapon to isn't working properly, making it my primary concern.

                I have no idea why the "grip" bones aren't working, the only thing I've noticed is that the two bones aren't listed in the Dope Sheet Summary for the vast majority of the animations I've created so far, but I'm not sure whether that is something to be concerned about or not.

                Comment


                  #9
                  Originally posted by Hungry Moogle View Post
                  guess its possible that the Selected Objects option didn't work as I intended
                  Er... no... the function worked exactly as intended - but a bone is not an object.... the armature is.

                  So... here is an abstract of the normal blender to ue4 workflow.

                  1) Import in an FBX (with or without animation)
                  2) Rig / or otherwise do the required setup and scaling
                  3) Animate / Work
                  4) Export to FBX
                  5) Import into UE4
                  6) Apply real materials instead of the **** from blender.
                  7) Put it where it needs to go (anim bp? map/level? etc.)

                  So - going with that... Just export from UE4 the animation in question as an asset with a preview mesh. (you can actually watch me do it on some of my vids...
                  https://youtu.be/NYbJBocZUTM?t=303)
                  Import to blender
                  Work on it (remove the bones in edit mode!)
                  and then import it into UE4 again selecting None as the skeleton to generate a new one.

                  Also, note that you can NLA Bake only the Selected Bones - and that if you click the animation export options you have an option to export only the deform bones.
                  So, ideally you can select the bones in Pose Mode that you need to have in UE4, Bake the animation, Turn on the Only Deform during export, and have only those bones within the armature in the new skeleton you generate in unreal.

                  Then ofc you need to retarget all the old animations to work with this new skeleton.

                  Let me know if that helps.

                  Comment


                    #10
                    I finally figured out why the bones that the weapon is suppose to attach to isn't working. Its turn out that I forgot to add the bones to the main mesh/armature model Blend file, only adding them to the animation Blend file. Once I added the bones and re-exported the model as a FBX file into Unreal Engine, the bones were properly working. The Inverse Kinematic controller bones that are incompatible with Unreal Engine are still there but they're not really a priority right now or perhaps ever.

                    However, what is a problem though is that after adding the socket to the grip bone and choosing to add a preview of the weapon model results in the preview being ridiculously larger than it's intended size. As to why this is happening, I have no idea as I checked the original Blend file of the weapon to see if the scaling units were wrong or if the scaling hadn't been applied, since that has caused me some problems in the past, but there didn't seem to be any scaling issues that I could see. Moreover if I drag the weapon out directly into the level in Unreal Engine, the weapon appears at its proper size, so I not sure if the problem lies with the weapon model itself or if this issue is restricted to the preview only.

                    I also tried shrinking the preview weapon but I could only shrink the weapon so far before it would disappear entirely, so that's not really a solution either.

                    I only thing I've noticed out of ordinary that might be connected, is that after adding the socket to the "grip" bone, a large diamond-shaped outline larger than my character model appears, extending outwards from the location of the socket. I don't know what this diamond-shaped outline is, as it doesn't appear in the video tutorial I've been using [Link: https://www.youtube.com/watch?v=SPvx...qhDR6&index=20]. Whether the diamond outline was perhaps something that was added to Unreal Engine in the subsequent two years after the video was originally posted or something else entirely, I don't know.

                    Comment


                      #11
                      Argh, it's been way to long since I last addressed this issue, anyway though, since the last time I posted here I found some additional information about why my weapon model is ending up so gigantic when I place it in the "grip" socket of my character model.

                      After searching online for a bit, I came other posts of people experiencing the same problem as me like in this link. Evidently, the giant diamond-shaped outline I mentioned before that appeared around my character is actually the "grip" socket itself, and for whatever reason the socket is being scaled upwards to a massive degree. The result is that any object I that attach to the socket will be scaled to the same size, hence why the weapon ends up gigantic when attached to the socket but appears in it's proper size when I drag it out into the main scene.

                      After reading all of these similar plights as mine though, I haven't been able to identify any singular fix to this problem. Does anyone here know to how deal with this giant socket issue?

                      I can manually scale the socket down to size but I'm not sure if that is the most optimal approach to fixing this problem.

                      Comment


                        #12
                        Click image for larger version

Name:	socket_transform.png
Views:	124
Size:	15.0 KB
ID:	1658140
                        Are you not seeing the transform controls?
                        check that relative scale is 1 all across.

                        Comment


                          #13
                          I can see the Transform Controls and the Relative Scale is 1.0 across all axes but for some reason attaching a object to the socket results in the attached object being expanded in size to a ridiculous degree.

                          Whatever the problem is, its not with the Weapon Object I created as I tried to attaching a default cube from Unreal Engine 4 onto the socket and the cube was also greatly expanded in size.

                          While I was reading other people's experiences that were similar to my current predicament, I saw a couple of posts that said the problem with the socket is the result of a glitch involving adding sockets to a model imported from Blender. I have no idea whether or not this is actually the case as I can't seem to find any other causes for this issue.

                          I can manually adjust the scale of the socket myself but my concern with this is that I don't know what scale the socket is being sized to. You see if I scale the socket down to 0.01 or 1% of its original size than the attached object ends up too small, whereas if I adjust the scale to 0.02 then the attached object appears to be at its intended size. The keyword though is "appears" as I can't say for certain if the attached object and by extension the socket is actually at its proper size or not, even with my character model with the equipped weapon opened in Blender as a visual reference. For all I know, the Weapon Object/socket could be a bit too big or too small, and while this isn't a big deal for this particular object, it is for things like clothing that need to maintain a 1:1 scale with my character model in order to prevent things like clipping from occurring.

                          Since I had to reduce the socket's scale to 0.02 or 2% of its original size in order to get the attached weapon to appear at its relative proper size, I would have to conclude that the socket isn't being scaled by a factor of 100, but I also don't know if its necessarily being scaled by a factor of 50 either, it could be 49 or 48.554 for all I know. This why I would much rather figure out how to fix this problem so that attached objects will appear at the intended scale without having to waste time fiddling around with the Relative Scale to try and match the original object's size.

                          Comment


                            #14
                            What happens if you delete the socket and add it back?
                            Even better, add another socket to the same bone and see if the scale is huge or not...

                            If it is, you should consider saving out a copy of the project, removing everything except the character mesh/skeleton/weapon and submitting a bug report with it.

                            Comment


                              #15
                              What happens if you delete the socket and add it back?
                              Even better, add another socket to the same bone and see if the scale is huge or not...
                              I tried doing both of these things but it didn't make a difference. Out of curiosity, I tried adding a socket to the head bone and just like the grip bone, the resulting socket was over-sized. So whatever the problem is, it would appear to affect the entire armature rather than just one bone, which I figured would be the case.

                              If it is, you should consider saving out a copy of the project, removing everything except the character mesh/skeleton/weapon and submitting a bug report with it.
                              I guess I should get around to doing this since I'm guessing that there's nothing else that can be done at this point.

                              I suppose I'll have to keep going forward on my work continuing with the socket scaled down to 2% of it's original size and hope that it doesn't cause any issues down the road.

                              Getting back to the subject of spawning a object during animation, I need help with trying to figure out how to setup the blueprint for the Animation Notify intended to call the Weapon Object into the swinging animation.

                              I haven't been able to find any tutorials online how to accomplish this, the closest being this one:

                              Link: https://docs.unrealengine.com/en-US/...nts/index.html

                              But I'm not sure whether or not this guide is applicable to what I'm trying to do, so I instead tried using a more general tutorial on attaching a object to a character via blueprint with the hope of being able to apply it to the Animation Notify blueprint. No such luck though, as my efforts have not gone well at well:

                              Click image for larger version

Name:	anim_notify.png
Views:	141
Size:	97.2 KB
ID:	1659640

                              Can't say I'm surprised it didn't work. Shouldn't the target for the Get Socket Transform be the character mesh not the weapon? I couldn't find any way of setting the target as the character model, assuming that is what I'm supposed to do. I wouldn't know seeing as I have absolutely no idea whatsoever as to what I'm doing, which is why I need with this.

                              Comment

                              Working...
                              X