Announcement

Collapse
No announcement yet.

Cable Component Plugin for UE4

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

    Cable Component Plugin for UE4

    Lead programmer James Golding is back to share a cable component plugin he created for UE4. Read on below or check out the original post on our blog at unrealengine.com!


    Here at Epic, we get one day a month nominated as ‘Epic Friday’, on which we can work on pretty much anything we like. A couple of months ago I worked on a really simple ‘cable component’ using rope physics for hanging up in levels, to add a bit of life. It’s an effect that has been seen in other games for years, but I wanted to see how easy it would be to add as a plugin to UE4! Here is what I ended up with:

    https://www.youtube.com/watch?v=WdrtNUSJZkY

    Simulation

    To do the actual cable simulation, I used a technique I’ve played with a couple of times called ‘Verlet Integration’. It is very well known in game development; you can find all kinds of articles about it, the first one I remember is from Thomas Jakobsen (http://graphics.cs.cmu.edu/nsp/cours...s/jakobsen.htm).

    The idea is to represent the cable as a series of particles, with ‘distance constraints’ between them. The particles at the ends are ‘fixed’ and move with whatever they are attached to. The ones in the middle are ‘free’ and fall under gravity. Each step, you update the velocity and position of each particle, and then move them to satisfy the constraints. The ‘stiffness’ of the cable is controlled by the number of times we iterate to enforce the constraints, each step.



    I won’t go into the maths here, but if you have the UE4 source code it’s only about 60 lines of code in the UCableComponent class, inside the functions VerletIntegrate and SolveDistanceConstraint.

    Rendering

    Now that I had a nice chain of particles bouncing around, I needed to render it. This was a pretty good test case for creating a new type of geometry in UE4, and it turned out to be quite easy. I had to create a new FCableSceneProxy class, which is the renderer representation of the cable. Each frame I pass the new particle positions from the simulation (which is done on the main thread inside TickComponent) to this proxy, via the SendRenderDynamicData_Concurrent function. On the render thread I lock and update the index and vertex buffers to make a ‘tube’ mesh. For each vertex I need to calculate a position, a texture UV, and three tangent basis vectors. X points along the cable, Z points straight out from the cable (the normal), and Y is perpendicular to X and Z.



    I expose properties on the component for number of sides, radius of the tube, as well as how many times to tile UVs along the cable.

    Attachment

    Now that I could see the cable and play with it, I wanted to attach it to things. Unreal Engine 4 already allows any SceneComponent to be attached to any other, so I just added an option to attach the ‘end’ particle to a different component, with an offset. The final details for the cable look like this:



    And that was it! You can try this out by adding a Cable Actor to your level (or a Cable Component to a Blueprint). It is certainly a fun addition to UE4, but there is a lot more that I would like to see added:

    • Add collision with the world.
    • Response to forces, explosions etc.
    • Multithread the simulation instead of doing it on the main thread.
    • Stop rebuilding the index buffer every frame as it doesn’t change.

    What about you guys? What would you like to see added? Find me over on twitter at @EpicJamesG or let us hear about it below! Your feedback on our tools and these tutorials is important to us.
    Attached Files

    #2
    Neat!

    Is there a relatively easy way to generate these at run time (i.e. during gameplay) rather than placing in the editor?

    Comment


      #3
      Awesome! Just what my project needs!

      Comment


        #4
        This can be an insanely useful(and fun ) tool with world collision.
        FREE VR Drum Kit Project
        FREE Color LUT Collection
        FREE Physics Driven Spacecraft Project
        FREE GTA Style Vehicle Interaction
        Dynamic DoF(Depth of Field)
        Camera Crossfade

        Comment


          #5
          This is extremely cool. I plan to try this out sometime.
          Matthew Slanchik Game Design and Development
          www.Slanchik.com

          Comment


            #6
            Great feature!
            Any chance of making a tutorial of it using blueprints?
            Or at least more details on how to make it?

            Thank you.
            A 3D Adventure Game developed using Unreal Engine 4

            Comment


              #7
              Love this! I was needing something just like this earlier today to prototype something for a video render in matinee (that has moving meshes that I wanted naturally moving cables dangling from) and this looks like it'll do the trick! thanks

              EDIT > 10 minutes later, I can confirm this works like a charm. Got the exact thickness, length and stiffness of cable I needed going from a rotating machine arm to it's sliding front cover (attached as child to arm, attached cable to sliding cover) run the animations and sure enough it moves and reacts like cable. I had no idea this was sitting there in UE4 until I saw this post!

              Thanks again. Nice work.


              To the guy above, drag the cable actor into your level. Position it on point A (If point A is a mover/animating mesh then attach it as a child), in the cable actor properties you can set all the relevent stuff like length, segments, amount of polys for a smoother cable, stiffness, material etc and the 'attach end to' is simple (use the dropper to click on the mesh in the viewport) and it 'just works'. I didn't touch blueprint but my needs were simple - Attach a cable between two related moving meshes (that move at the same time and are simulating part of the same machine) the cable just gives it a bit of life vs the usual static mock cable tube.


              One question to James if I may, at launch the cable instantly reacts as if it's had some force (even though it's attached meshes start out stationary) it's like it pops into life rather than using it's rendered resting state as it's starting state, if that make sense? if so is there anyway to bypass it so when you hit play/sim the cable doesn't bounce wildly as if it's been hit? I looked through the parameters but couldn't find anything. Thanks.
              Last edited by Sharpfish; 04-10-2014, 03:12 AM.

              Comment


                #8
                Originally posted by Sharpfish View Post
                To the guy above, drag the cable actor into your level. Position it on point A (If point A is a mover/animating mesh then attach it as a child), in the cable actor properties you can set all the relevent stuff like length, segments, amount of polys for a smoother cable, stiffness, material etc and the 'attach end to' is simple (use the dropper to click on the mesh in the viewport) and it 'just works'. I didn't touch blueprint but my needs were simple - Attach a cable between two related moving meshes (that move at the same time and are simulating part of the same machine) the cable just gives it a bit of life vs the usual static mock cable tube.
                Thank you.
                A 3D Adventure Game developed using Unreal Engine 4

                Comment


                  #9
                  Originally posted by Sharpfish View Post
                  One question to James if I may, at launch the cable instantly reacts as if it's had some force (even though it's attached meshes start out stationary) it's like it pops into life rather than using it's rendered resting state as it's starting state, if that make sense? if so is there anyway to bypass it so when you hit play/sim the cable doesn't bounce wildly as if it's been hit? I looked through the parameters but couldn't find anything. Thanks.
                  I saw this too but have been unable to track it down thus far If anyone want's to dig in and fix it and make a pull request on GitHub, that would be great!
                  Lead Programmer - UE4 Animation/Physics/Audio Team - Epic Games
                  Twitter: @EpicJamesG

                  Comment


                    #10
                    Is it Possible To "shoot" the Cable out? Like I Line Trace to one Spot and than to another one and let an Cable Spawn with these specific Start and End Locations? I tried to create this but I just can't make the End Location happen and can't change it in my Blueprint. The Start Location is always also the End Location, I would like to see an "Set End Location" Function to control that value or is it possible to do otherwise?

                    Comment


                      #11
                      Originally posted by JamesG View Post
                      I saw this too but have been unable to track it down thus far If anyone want's to dig in and fix it and make a pull request on GitHub, that would be great!
                      My post seems to have vanished after I hit reply.

                      Thanks James for your reply, It's certainly not the first time I've come across simulated physics that have to 'warm up' so to speak before being ready for prime time (particle systems in general tend to be that way? I'm not sure). It's not a deal breaker because there are work arounds (camera delays if for matinee sequences, or if in game simply they would have stopped bouncing by the time the player sees them - typically).

                      I have noticed in the editor the cables can disappear (but are ok in game/play mode). This occurred after click drag copying a cable, and changing it to attach to another mesh. The cables then became erratic in display, based sometimes on small distance or angle changes (of the editor camera - in perspective/3D viewport). I'm only using a messy test level at the moment so it may well just need a rebuild and clean up but thought I'd put it on record in case anyone else notices.

                      Comment


                        #12
                        I once did the same thing in UDK, but since it was meant as part of a destructible environment (thanks for the destructible meshes BTW) I created it rather differently: I created a cable mesh in 3DS Max, and used a number of bones along the mesh (very much like the free particles discussed here), and created bodies for them in PhAT. I would then attach the first and last bone using physics joints to other actors. This allowed for interaction with physics and also allowed me to "tear" the cables using the joints' break force. Seeing this post got me wondering: which is the better solution in terms of performance?

                        Comment


                          #13
                          Is there a way to download this plugin? Thanks.

                          Comment


                            #14
                            It's already in UE4 - in the classes browser (cable actor)

                            Comment


                              #15
                              Very cool tool, I love to see new and exciting real-time solutions like this. I do have a question about the system though. Would it be possible to have the particle positions drive a skeleton instead of the final thing deforming vertices? I would think (you will have to set this me straight on this) you would be able to "drive" much more complex meshes with a skeleton rather than deforming the entire mesh. I'm sure everyone has seen people use a similar set up in Maya where you drive joints with a dynamic hair system or ncloth and then those results are baked down. It would be awesome to see this be a dynamic process instead of a pre-baked solution.

                              Comment

                              Working...
                              X