HOW TO MAKE CUSTOM HAND ANIMATION SNAPPING FOR YOUR STATIC INTERACTIBLE OBJECTS IN VR UE5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up everyone today I'm going to show you how to make custom grabs for objects with the preview we have right here so you could see where your hands will snap for only static and interactable objects what are we going to do today I specifically made a motion controller so our template works the way that our hand mesh is attached over controller so what we going to do today we're going to do custom snapping only for static object what do I mean by this so here is how our functionality works when I grab the thing my hand detaches from a motion controller and it goes to an object by my motion controller as you can see here it's still in the world it's my literally my hand in my motion controller and just want to make sure you understand what is happening right now this motion controller is a fake static mesh that you actually don't see in your regular VR game I just made it so you could see what it's actually happening because this motion controller you see right now on your screen is visual representation of your real motion controller in your room the one you have in real life but actually the hand is just a static match that is attached to controller so by detaching a hand and attaching to some kind of object we can make an illusion that we are actually holding this object but the actual movement will be programmed by location of this controller you see right now on your screen in our real world and here is what I mean for illusion so once we grab a slider you can see that our slider follows the motion of our motion controller like this and motion controller position is projected onto the line right here so we actually move the object by our motion controller so you can position it anywhere and our hand is attached so that's what I mean by creating an illusion of holding an object and once we release it our hand snaps back to our original position so here's what I mean what it can be used for like levers for maybe some sliders right here and maybe some other objects that will use this functionality so the functionality is again following I'm explaining it again I really need you to understand so as I've shown recently the hand attaches to for instance the lever and motion controller is still somewhere in the world it's your real motion controller so once you move your motion controller IT projects the movement to the lever and it makes the following movement M right here so it actually pulls the lever downwards and your motion controller is somewhere here so this movement is happening the same happens to the switch so once we grab the switch as I've shown right now hand attaches to the switch like this and motion controller is somewhere still in the world and we just project the movement of motion controller to the cylinder axis for instance here and once we we move our motion controller we move it like this our hand with cylinder is also moved but our motion controller isn't invisible and that creates the illusion of moving an object so I hope you really got it so first thing we'll have to do is to store our hand left and hand right relative transform because once we detach our hand we want to keep a reference of where the hand should be attached back so let's go ahead to our review our P let's go to our event graph and just quickly go ahead and make a function let's call it store hence initial position like this and what we going to do here we're going to get our hand left and hand right we're going to get relative transform and the same we're doing for our handro and we're going to promote to a variable so left hand relative transform and right hand relative transform like this and we're going just to connect it this way hit compile and safe go back to your event graph and put this function on event begin play since we want to do it once we spawn so just drag this function to here it should be on event begin play hit compile and save what we're going to do now we're going to create a punk controller that what I saw would work the best when you want to separate your functionality from your VR Pond like in separate Blueprints and it also seems like more professional so that's also a good way to learn let's go ahead right click we're going to create a blueprint class and here we're going to click on all classes and search for player controller make sure you click this one and select and let's call BP VR player controller so what we're going to do now we need to create the player controller to our game mode so let's go to our edit project set we're going to search for game mode VR game mode and here instead of player controller class player controller we're going to select our newly created BP VR player controller that's been done now we are going to create couple of interfaces we're going to use in our future so let's go ahead right click in the folder blueprint and blueprint interface so basically interface allows us to communicate with blueprints without having a direct reference between them so basically if you have one blueprint you can call some action from interface and other blueprint will react to this action so let's go ahead and call it BPI hand snapping we need blueprint interfaces because we are going to have separate actors as you can see here and it's going to be separate blueprints so this one hand is a separate blueprint and we need somehow to communicate with this blueprint through our graph component so that's why we need interfaces so let's double click on it and we are going to create three functions here the first one is attach hand to an object and here we're going to have inputs so the first one is going to be our snap transform that will be the location where we want to snap our hand so it's going to be of type transform afterwards we'll have a skeletal mesh that will represent our skeletal mesh hand so skeletal mesh it will be of type skeletal mesh component so we need our transform we need our hand afterwards we'll need our blend space so this variable will actually dynamically adjust our animation of our hand so that's what you have seen with the box so hands have specific animation so let's call it blend space and it's going to be of type blend space like this afterwards we're going to create another variable it's going to be a parent component that will be basically a parent component where will attach our hand you will see it in the blueprint I'll show you how it works and the last one we're going to pass a motion controller right here and it's going to be of type motion controller component like this and make sure your parent component is of type scene component this one so double check your inputs right here because it's essential not to miss one then we're going to hit compile and save afterwards we're going to create another function and we're going to call it snap hand position so we will have only two inputs here the first one will be our skeletal mesh and it's going to be a skeletal mesh component don't freak out if you don't understand what is happening right now we're just making some prequisites for what we will be doing in the future and I guarantee you will understand what each of those inputs will do so and another one here is going to motion controller and it's going to be of type motion controller component like this hit compile and save and last function we have to create here is going to be release hand from object and here we'll have three inputs the first one is motion controller it's going to be of type motion controller component then we have hand skeletal mesh it's going to be of type skeletal mesh component and last input will be original hand transform and it's going to be of type transform okay we're done with this BPI we are going to create one more basically it will be responsible for changing the animation of the hand so again blueprint blueprint interface and let's called BPI hand animation like this and inside of here we're going to create a function we're going to call it update hand blend space animation and this function will only have one input it's going to be our blend space animation and it's going to be of type blend space like this hit compile and save okay finally we can do some coding so first of all let's go to our grab component we're going to slightly modify it so what we're going to do is that we're going to go to our Tri grab and we are going to add one more input so this input will be our skeletal mesh and it's going to be of type skeletal mesh component so once we take something we want to snap our hand mesh to the object therefore we need to keep track of this hand mesh so this will be a type skeletal mesh component like this and let's go ahead move all of the code to the right and we are going to promote our motion controller reference so let's go ahead we can see here that we already have a variable so we can go ahead and delete it from here and put it right here and we don't need motion controller so we can directly connect this pin to here like this and afterwards we need to promote our skeletal MH also to a variable maybe let's called it first hand skeleton so in future you might want to implement two heading grabs so that's why I'm calling it firstand skeleton because we are going to release the object if we grab it with another hand while already holding the object so that's the reason like this and connect the execution pin to the sequence so afterwards just for the purpose of everything looking beautiful we're going to add one more grab type so go to your content folder search for grab type and we going to add another enumerator now let's called onehanded static object grab like this and let's move it to the front I would say like here and come back to your grab component and you'll see here that our one-handed static object WAP appeared right here so what we're going to do we're just going to set his health to True nothing hard and go ahead to your TR release function and also connect one handes static object WAP to is held false like this so come back to your Tri grab so in here once the grab is successful we'll create an event dispat and we're going to call it first hand grab so usually I'm calling everything Firth hand because maybe you will want to implement second grab functionality so we have First grab so let's drag our first hand grab here and call it what we want to do we want to add some inputs to our event so let's go ahead and click on our event in our event dispatchers and we're going to add first input is going to be our motion controller reference so motion controller reference is going to be motion controller component and another input is going to be our hand skeleton so hand so first hand skeleton like this it's going to be a skeletal mesh component like this and afterwards we're going to get our component is going to be our motion controller reference we're going to connect it right here and our firstand skeleton we have saved it in a variable right here so let's drag it in the same spot and connect to here hit compile and save afterwards we leave all the code here as it is so we are done with our functionality in TR grab now let's go to try release so in TR release since we had our dispatcher for grabs we need the same dispatcher for release so let's go ahead and create another dispatcher we're going to call it first and released like this and we're going to add three inputs now because when we release you remember we created the variables in VR Pawn where we stored initial relative transform of our motion controllers so let's go ahead and at this transform we're going to pass it through our VR Pawn so we'll have original hand location it's going to be of a type transform then we'll have another variable it's going to be our motion controller and type is going to be motion controller component like this and and afterwards we're going to add one more input and it's going to be our skeletal mesh and it's going to be skeletal mesh component like this and let's call our first hand release after call UND dropped so we need to take this original hand location from somewhere and actually where we can get this original hand location is only from passing to tr release function so click on your TR release and add some inputs so we're going to add motion controller is going to be motion controller component then we're going to add our original hand location is going to be of a type transform and then we're going to add our skeletal mesh and it's going to be skeletal mesh component and all we have to do is just to connect those pins hit compile and save so now that's it for modifying our TR grab and TR release so after we are done with this let's go to our VR Pond since we want to pass pass our new variables to our try grab and try release so we are PA and we are going to its event graph and as you can see here in our grab left and grab right we have additional variables for our try grab and try release so what we going to do we here since we are grabbing with our left hand so I'm looking on I a grab left we need to pass skeletal match so the only skeletal match that is responsible for left hand is our hand left so let's go ahead and do it like this so with this part when we want to Interchange our hands if we already hold something we'll do it later so so now we have to do with tri so with tri we're going to do the same we're going to take our motion controller left crib because it's we're doing everything for our left hand so motion control left grip pressing here original hand location we created original hand location for our hand left this variable and our skeletal mesh is our hand left too like this afterwards let's do the same for our grab right so here our skeletal mesh will be hand right and afterwards in our TR release we're going to get our motion controller right grip original hand location ride so right hand relative transform and skeletal mesh is our hand right like this so make sure you did everything as shown on your screen hit compile and save so now let's go ahead and create our preview hand that will be attached to object so we could see where our hand will be attached so right click blueprint class we're going to create an actor and let's code BP hand preview like this let's double click on this blueprint open it so what do you want to have here here is that we want to have our default SE route we'll add an arrow we need some kind of component that we can attach our hand to so the best choice I've come up with is actually Arrow it will not do any sense in our game it will be our parent component the one I talked recently about so that's where we will attach our hand and finally we need a preview mesh so let's go ahead and add athetic mesh so as you've shown in this photo so those two hands are two of those blueprint two BP hand previews right here so we need a kind of preview but we need to add static mesh but for our hand we don't have static mesh so let's go ahead and create one so we'll search for our mannequin XR hand let's maybe create an our I don't know right we're going to make static mesh from this hand so click on make static mesh and I'll save it in content browser and let's call preview static mesh like this we're going to hit save and now come back to our blueprint and in this blueprint now I can select my static mesh and I can choose my preview hand like this and now make sure you choose your arrow and you rotate it 90° upwards so so it would be better to position our hand in the future and maybe let's move it a little bit to the bottom not that much I'll turn off the snapping and maybe I'll position it somewhere here now we can hit compile and save so now we can go ahead and add a couple of variables so the first variable will be our custom static mesh to display so we could set this variable from another blueprint and we could see how our static mesh would look like on an object so it will be of type static mesh like this and then we will create a variable is left so it's also for our visual purpose so it's going to be of type Boolean and afterwards we'll create one more variable it's going to be our anim blend space so it's going to be of type blend space this will be an animation it will be assigned to a hand like this and make sure that you select all of those three variables instance editable by pressing on this icon right here so since we have our anim blend space we have our custom static match to display we need to create those variables because we have nothing to display right now and we have no custom animation so what I'm going to do I'm going to look for any hands right here maybe I'll take just the regular one like this going to skeletal mode and I will make my hand look like it's climbing something so I will make something like that like this okay so now it looks like I'm holding some object so I think that's fine so what we're going to do now we're going to create esset create animation current pose and what we are going to do we're going to save in our animation folder and I'll call it SK man XR Cube hold and don't finish yet because what we'll have to do we'll have to create a blend space with this animation so let's go ahead create esset blend space 1D and we'll save it to our content browser and I'll do something like blend space 1D Cube hold like this so afterwards let's find our animation we saved it to animation and it's Cube hold so we're going to selected and we are going to create static mesh now we need now we create our preview mesh basically we're going to say it to content folder so Hand mesh Cube hold preview I'll call it like this and now we go to our blend space the one the blend space we've created and we'll put our Cube hold animation right in the beginning on the zeros one hit contrl s and save so let's go back to our hand preview we don't have now to assign those variables we just created for future so let's go ahead to our construction script and we're going to modify our construction script a little bit so what we're going to do we're going to get our custom static mesh to display and we're going to check if it's valid in case it is valid we are going to get our static mesh let's call head mesh and we are going to set static mesh to our custom static mesh to display like this afterwards if we can check if it's left so in case it's left we're going to get our head mesh set scale 3D and make sure you choose that relative scale 3D and it's going to be minus one 1 and one and again that's just for the visual appearance it's not something that will manage our code so afterwards we hit compile and now we can go to our event grab so what we have to do now is that we want to display our mesh in our preview but once the game begins we don't want to see any mesh our Cube so let's go ahead and on our event begin play hand mesh and we're going just to destroy component that simple so if you see if I put this hand mesh preview in our in my level and after I launch my simulate our hand will disappear as well as the eror so that's the beauty so now let's go ahead and we need to modify our animation too so let's look for our mannequin XR and that's basically the animation here is responsible for our regular hand grab but what we have to do is once basically we use our custom snapping to an object we'll have to assign this animation to our output pose so what we actually have to do go ahead and click on our class settings and we can see our implemented interfaces here we're going to add an interface we're going to select BPI hand animation like this hit compile and save so now you can see that interfaces tab appeared here let's click on it and double click on update hand animation blend space so this event will be only triggered once we call from some kind of another blueprint it's like listening to this event for this purposes let's go ahead and create a Boolean variable and let's call it use custom animation and as you can see here it has an input of blend space animation that will be our custom animation we have created so let's go ahead and promote it to a variable is going to be our blend space animation we can even call it custom blend space animation for better understanding like this and we're going to check if it's valid it's valid so in case it is valid what we are going to do we're going to set our use custom animation to True since we have passed something to this variable it means we want to set our custom animation so we set this Boolean to true and otherwise we set it to false like this afterwards we'll go to our anim graph and here is the tricky part what we going to do we're going to blend all of our existing animations so blend we're going to create a state machine so we'll have only one state in this machine let's call it custom animation State machine like this and inside of this machine we will have only one state add State and is going to be custom animation so in this custom animation we go double click on it and we're going to blend space player and here we're going to insert our custom blend space animation but as you can see there is no input so what we have to do is to click on our blend space player and here we have to bind our blend space on custom blend space animation like this and now we are able to connect it so our X and Y is in zero so basically this zero will trigger Zero's element right here so as you can see our animation here is at zero so and connect this to Output animation Poe hit compile and save go back to levels and now we are going to blend this animation return from here to here and we are going to do it only in the case when our use custom animation is true so we going to click on our blend and change our Alpha input type to Boolean and connect use custom animation to here hit compile and save so now since we have our preview let's actually delete all the cubes from our level because we no longer need them we need only one to test and let's edit its blueprint so in here we want to see how our hands will look like on our Cube and here we're going to look for child actor so let's call it left hand and here we can choose our child actor class and it's going to to be our BP hand preview hit compile and save now as you can see our hand has appeared here so that's going to be our preview in the level let's actually position it in the right way like this and you remember we have created a static mesh so if you go ahead and compile you can expand child actor template and go in default and you will see that you have our three variables we've created in our BP preview so custom static match to display so I'll select my head mesh Cube hold preview like this as you can see now it's previewed afterwards we're going to select our and in blend space so it's going to be our blend space 1D Cube hold and this hand since we hold it left hand is going to be left you can see it like Turned so let's position it in the right way like this it looks like we're holding a cube right now and afterwards what we going to do we're going to duplicate this left hand we're going to call it right hand so what we're going to do we're going to change its Y location to positive and it's going to be here now we can untake is left and we can turn our hand 180° like this and it's symmetrical now so again if you put this Cube into the level you will see that you have like kind of hand preview where your future hands will be attached to but if you run the level they will disappear so no worries that's just for our visual appearance so now we can go to our grab component and we're going to make our functionality for snapping so now it's going to be a little bit tough but in the end I promise again it will be all clear I'll go through everything so what we have to do now we in our grab component let's go to our event grab and create a custom function so custom event we can call it snap skeletal hand like this and here we're going to have four inputs so the first one is going to be motion controller is going to be of type motion controller component like this then we have another input it's going to be our snap hand actor left and it's going to be of type child actor component we're going to have the same variable is going to be our snap hand actor right and afterwards we'll have our skeletal mesh it's going to be skeletal mesh component so as you can see here we have our snap hand actor left snap hand actor right so and as you have noticed in our Cube we have adjust for our right hand and left hand those are two variables right here and our skeletal mesh will be passed through our gravable Cube so if we want to snap our skeletal hand we need to check first which motion controller we are using left or right so let's go ahead get motion source and we check if it equals to left grip because our motion Source in our VR Pawn I can show you right now because as you can see in VR Pond motion controller right grip has motion Source right grip and left one has left crib so here we're checking if it's left crib so on this point we stop a little and we come back to our hand and we come back to our preview hint BP preview H here what we have to do we have to add an interface so let's go ahead and cl settings interfaces and we're going to add interface it's called BPI hand snapping and as you can see here we have three functions appeared so the first function we're going to do is our event snap hand position this one so after we've added our event snap hand position we are now going to our BP VR player controller that's a lot guys I promise you will understand this then you will go to your event graph and in our class settings we're also going to implement interface so you press f BPI hand snapping and here we're just going to double click on our attach hand to an object like this hit compile and save so now we come to our BP hand preview and here we need to let our BP VAR player controller to know which hand we're attaching and then in here we're going to write the attachment functionality so let's go ahead from our event snap hand position we're going to get player controller we're getting our BP V player controller right now and we are going to attach hand to an object so we're going to trigger this function right here and as our skeleton mesh we pass we pass our skeletal mesh our blend space we have created this variable recently so our custom enim blend space we're going to connect here then our parent component is going to be our arrow and our stance form we want to snap our hand right in this point right here so we're going to get our Arrow get World transform and put it as snap transform and our motion controller will be our motion controller like this hit compile and save now we have somehow to get to this event right here so the way we're going to do it is actually from our grab component so let's go ahead to our grab component back and in here in case we're gripping it with our left hand we're going to go ahead and get our snap head actor left child actor this one and we are going to snap hand position so we now we are going to use this message right here and it's going to be untrue our skeletal mesh is going to be our skeletal mesh hand so we can drag right here create a reroute node and connect to our skeletal mesh and our motion controller is going to be our motion controller like this afterwards in case it falls we're going also to get our child actor but now from our hand actor right so this way snap hand position is going to be on false motion controller we connect right here and skeletal mesh is going to be our skeletal mesh hand like this hit compile and save and now we need some help to trigger this event so the way we're going to do it is that we're going to get to our grabbable small cube and you remember in grab component on our Tri grab we used our call firstand grabed so now we can access this event from our grabbable small cube so so let's go ahead in our event grab and we're going to left click on our grab component and as you can see we have our first hand grab plus icon right here so click on it we're just going to promote our first hand skeleton to a variable like this maybe just in case we'll need it in future and now we have to trigger our event here snap skeletal hand so the way you're going to do it we're going to get our grap component and snap skeletal hand like this so now our motion controller is going to be our reference from here our snap head actra left is going to be this one our snap hand actra left is going to be left hand child actra component right hand to here and skeletal mesh hand is going to be this one hit compile and save okay so for now just for you not to be scary and confused what is happening in our VR Pawn make sure you check the beginner tutorial on VR template we are grabbing an object then we're going through all those functions right here and we are getting on this call for firstand grab on this stage we grabbed our Cube we grabbed our cube in the level this this cube right here in the level so we are going to call firsthand grabed and we're going to trigger this function right here so firstand grabed once we trigger it we are going to our grab component and we pass our motion controller and our hand skeleton that's our hand skeleton from our motion controller then we go to our grab component we figure this function then in our grab component we come here so from snap skeletal hand we go here here to our grab component and now we are qualifying which hand is going to be snapped right or left so here we decide this and afterwards we are going to our child actor it means that we're going to our hand preview and we're calling snap hand position so now we're here event snap hand position we need to pass the variables from here to our player controller and Trigger this attach hand to an object now we go to our player controller and in here we actually implement the attachment logic yes I know guys that's a lot that's a lot of things but after the tutorial just take time and just understand how it works if you don't see the way I do please take a lot of time after this tutorial and just just go through the code like yourself to the beginning so our VR player controller so now in this stage we know which hand we are attaching left or right and where we are attaching we are snap transform so what we going to do we're going to detach our hand so detach from component because now it's attached to our motion controller we're detaching it and make sure you have keep World everywhere and afterwards we're using the best function D engine I've I've seen so far because before this I was doing everything manually there is a go function called move component to so actually what it does it smoothly attaches component to location and rotation in the world and it does it really smooth and I was doing it all manually but now we have like a whole function for this and our component will be our skeletal mesh like this the location rotation we're going to snap our hand is actually this one snap transform so we're going to break transform here and our location and rotation we're going to connect here and we're going to force shortest rotation pass and over time uh I think 0.1 will work better so throughout 0.1 second our hand will attach to this cube right here so afterwards we're going to get our skeletal mesh again we're going to create couple reroute nodes like this and we're going to attach component to component and it's going to happen after this move component to completed so our parent in this case will be our parent component so we can drag from parent component to here we're going to snap to Target all the rules like this and our final step after our hand attaches we need to apply an animation go ahead and get the anim instance from our skeleton mesh get anim instance and you remember that in our animation blueprint so if I show you it right now we have created an event here here so event graph we have this event update head animation blend space so what we going to do is that here we're going to call this event right here so update hand blend space animation and our blend space animation now will be our blend space from here you can directly connect it to here that's it for our attachment hit compile and save so if we are able to attach our hand we need to be able to detach our hand so let's go ahead and double click on release hand from object like this and what we're going to do here is that we're going to attach our hand back to our motion controller so let's get our skeleton mesh attach component to component like this our Target is going to be skeletal mesh our parent is motion controller and we and our location rule is going to be world world world afterwards we also can directag from our hand skeletal mesh we can get we can get ANM instance we're going to call the same event here but now we are going to pass null here so that will actually return our animation that will set this variable to false and it will just not blend with our custom animation and return to our basic animations and afterwards we need to attach our hand back so let's copy this move component to right here and we are going to get our original hand transform we're going to break transform and our location we can put here here rotation here time we can leave the same and component we're going to attach our hand skeletal mesh to here and we can hit compile and save so now we come back to our VR Pawn we go to our event graph and as you remember I told that we're going to finish functionality here so in case we're grabbing an object already we are going to trigger this animation right here event release hand from object so let's go ahead and get player controller like this and we are going to release hand from object like this and we're going to connect this pin to here so here we need to release our opposite hand so if we're grabbing it was our left hand we need in this case if this condition is true release our right hand so motion control right grip hand skeletal mesh hand right and original hand transform right hand relative transform we can copy this code and put it here so in this case we're going to have motion control the left clip hand left and right hand relative transform we're going to replace with left hand relative transform like this hit compile and save afterwards when we release our hand we also want to use this function so let's go ahead and directag our TR release in our grab right to the right like this so what we can do here is that in this case we're releasing our right hand so we can go ahead and copy this piece of code from here and put it to here like this and the same way for our left hand we are copying this piece of code right here and pasting it to here so now I think we're finally done I hope everything is going to work out right now if we go ahead and in our level and we try to grab our Cube that's what I'm going to do right now so now if I go to my Cube and I decide to to grab it uh oh and yeah and I think I forgot to change my grab component type so if we go back to our Cube and we change it grab component so make sure it's set to one-handed static object grab and now as you can see your hand actually snaps to the cube so let's actually go ahead and rotate it because the positioning of our hands is actually weird so I will rotate it like this so you could see it this way so now as as you can see our hands snap really smoothly and if I already hold my cube with my right hand and I decide to grab it with my left hand my right hand releases like this so yep it works and now I'm just going to scw everything so you can understand it and let it sink in your head so what we doing we are chasing the grab components in our Cube so that's happening in our VR Pawn I'm opening my VR Pawn we are going our Tri grab right from the beginning I'm going through complete beginning I'm going to my grab component I'm trying to grab so we enter another grab function we managed to find a grab component out our Cube this Tri grab takes our skeletal mesh and motion controller and it doesn't know which hand it is yet so it passes those variables to our event dispatcher so this event dispatcher is getting triggered inside our Cube so let's open now a cube so it goes from here this event it's binded right here here so first hand grab so here we pass those variables and now we use another event dispatcher it's our snap skeletal hand we go back to our grab component so this sends all the information back to our grab component right here and it actually qualifies which hand we need to snap so here it actually checks and you may ask why do we jump from grab component to the cube and then from Cube to grab component and the answer is really simple because for our grab component it's essential to get the information from our Cube and in our Cube Cube we have those two children actor components so we grab those children actor components from our Cube we we bring them back to our grab component right here we qualify which hand we need to attach and we pass one of those children components to next event dispat your snap hand position so now it actually goes to one of those hands depending on which hand you grabbed it with and now it goes to the blueprint hand preview so now we open our BP hand preview and now it gets to here so grab component here qualified our hand and send the information about this hand to our hand preview in here H preview gets our custom animation the one we set in our Cube it gets our Arrow that's the component basically where our hand attaches to and it also sends its oral transform to event dispatcher attach hand to an object so this event here is now in our blueprint VR player controller so as you can see here it triggers this event right here attach hand to an object so in our hand preview it passes the transform where we need to attach our hand and animation we need to apply after attaching that actually What's Happening Here It detaches from our emotion controller so now hand becomes Itself by itself then it moves to this location that is right here and afterwards it finally attaches to this location after it has moved towards it and custom animation is applied and this event right here goes to our AP mannequin XR this event is triggered right here so from VR player this event now is triggered right here and we use custom animation we go to animation graph so this becomes true our custom animation blend space in our state machine gets returned and all our default animation blends with our new animation the custom animation and once we release so back to our VR Pawn we went through all of this of course here we check if our opposite hand holds the object to so this case we release this hand so we release it right here and you may ask where are we getting all of those information right here we're getting it from VR Pawn we are passing relative transform so that's where our hand mesh was before in our motion controller and we are passing our motion controller information so we are attaching this hand back so we are attaching it back to motion controller we're smoothly interpolating it towards our controller and we update animation to false so that our animation blueprint was not using this blend right here it was using its default one the same in our VR Pawn happens when we release so when we releasee we release hand from object object so it smoothly goes back to our controller again the same function as here and then we try release it in the grab components so we try release it using this functionality right here and this called firstand release is actually nowhere in our program we are not using it but I'll just made it for future tutorials and yes so that's basically all the functionality we have so now I will show you how to implement custom animation for your object in your game so I'll do now everything using what you have created so for this purpose I will just create another blueprint it's going to be easy one so I'm going to create a BP slider I'll create a symbol slider so we can go ahead and add a cylinder right here it's pretty big one I'm going to make it lower like this going to turn it 90 so let's see how it looks in the level okay that's pretty fine so now what we're going to do we're going to add our grab component it's going to be of type one handed static object WP and we're going to add child actors the one is left hand and the one is going to be right hand so now we hit compile we can select our child actor class it's going to be BP preview hand BP hand preview and here we do the same BP hand preview and now we actually need to add those previews what I'm going to do I'm going to our animation for our hand so let's go ahead and open our animation maybe just this one and I will slightly remake it so maybe I will just go ahead and model the animation right now so the way we're going to hold our slider so okay now it's just for the people who want to make the animations perfect and so that they didn't Clips through the object what you can do you can create a socket so we'll create a socket just for the sake of testing we will not use this socket anywhere so you can call it even test socket you can right click at preview AET and we can add cylinder here since I'm doing everything for cylinder the cylinder is going to be relatively big so we can make it smaller like this and we can position this Ed under our hand so like we hold the cylinder so using this way you are able to make the animation for your slider perfectly aligning with your hand so you can see the preview of the mesh you're attaching your hand to so now you can go ahead and adjust your bones so it looks like your animation here but I'm not going to use any preview meshes I'm just going to do the animation quickly just for the sake of tutorial but you can do it having the preview mesh and line your hand perfectly that's what I'm done with just it's not perfect it's a okay just for the sake of tutorial so what I'm going to do is that I'm going to create a static mesh from this so content is going to be mesh preview slider like this I'm going to save it afterwards I'm going to create esset create animation current post I'll going to save to animations so SK manic xar slider grab and afterwards I can go ahead to my content drawer I'm going to right click animation blend space 1D which to look for blend space 1D it's located in our Legacy blend space 1D is going to be for our SK manic n XR let's call it blend space 1D slider we can open it and put our slider animation inside right here so now all we have to do is to go to our blueprint right here so for our both hands we will go to our default choose our custom to display so it's going to be our slider like this and our anim blade space is going to be our blend space 1D slider and for left hand we can just choose our left hand like this so now let's position our hands so it's going to be this way our right hand and our left hand again it's not going to be perfect just for the sake of tutorial and afterwards after we are done with this we're going to go to our event grab we're going to go to our class so now all we have to do is to click on our grab component and add our firstand grab and and in here you can just copy the code from our Cube so I'll just go ahead to our Cube yeah you can just go ahead and copy all of this code right here and paste it in our slider like this you can connect your firstand skeleton right away to skeletal mesh and connect it right here hit compile and save that's it you have custom grab animation for your slider so the reason we use this event in every blueprint because maybe you want to have the following claic and you have access to motion controller so now your hand is on your slider it's not on motion controller anymore but you have motion controller and this is how you can actually rotate your slider using the motion controller position in the world so now if I go to my level and I will go to the slider I put there so now as you'll see don't pay attention to this controller I did it for testing you will not see it in your life we can actually grab our slider we can see and grab our slider where we put our hands and yep that's basically the end of the tutorial
Info
Channel: Yaro
Views: 274
Rating: undefined out of 5
Keywords:
Id: QwM9x79QqtE
Channel Id: undefined
Length: 43min 47sec (2627 seconds)
Published: Fri Mar 22 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.