How to interact with Foliage using Physics, Rigid Bodies & Skeletal Meshes in UE

Sdílet
Vložit
  • čas přidán 25. 07. 2024
  • Files are available as a Tier 2 reward on my Patreon: / ghislaingir
    Twitter: x.com/GhislainGir
    Mastodon: @GhislainGir@mastodon.gamedev.place
    0:00 Intro
    0:56 Physics Asset Setup - Bodies
    3:20 Physics Asset Setup - Constraints
    4:20 Physics Asset Issues
    4:58 Foliage Instances
    5:30 Blueprints - Swap In
    6:34 Blueprints - Swap Out
    7:24 Technical Notes
    9:35 Lightweight Instances
    13:02 Skeletal Animation Fade Out
    14:32 Collision Profiles
    15:49 Outro
    Here's how to setup a basic foliage interaction system in UE5 using physics, rigid bodies & skeletal meshes. I hope you'll like the video, cheers :)
  • Hry

Komentáře • 34

  • @ghislaingirardot
    @ghislaingirardot  Před měsícem +1

    A couple of things from all the feedback I gathered:
    1 - Static instances could be simply scaled to (0,0,0) for the skeletal swap, instead of removing/adding instances! You'd then need to store that index in the skeletal blueprint so you can revert that instance's scale back to its initial (x,y,z) scale to swap back with the static instance.
    2 - Static instances could be configured to have a simple spherical collision and overlap events could be triggered on your character to get instances you'd be overlapping with. The 'OtherComp' hit component could be cast to an FoliageInstancedStaticMeshComponent and the 'OtherBodyIndex' would thus point to the instance's index, to trigger the skeletal swap. That would allow you get rid of the 'get instances overlapping sphere' method and solve the spatial query problem by letting Chaos handle that optimization on its own.
    3 - The dual character capsule setup is unecessary. You can call 'IgnoreActorWhenMoving' function on the character's main capsule and provide the spawned skeletal actor to prevent the two-way interaction!
    Thanks to all of you for your very valuable feedbacks!

  •  Před měsícem +13

    I made similar thing about month ago and had most of the same problems and found few things.
    You don't need to replace skeletal meshes with static meshes, there is render static bool on skeletal mesh component, that renders it without bones and you can change it in runtime.
    I placed them in level as bp with sk components and tried to turn off tick on bp, but through insights I found that skeletal meshes are still ticking separetly, so you have to turn them off too, that was quiet heavy on CPU. There is also only tick pose when rendered option on sk component and you can also turn off simulate physics, when you are far from it.
    Disabling skin cache for sk asset can get you some performance, because you don't need it when its interactive.

    • @ghislaingirardot
      @ghislaingirardot  Před měsícem

      Oh, very interesting! Thanks for the info, I'll check that out.

    • @CAyou
      @CAyou Před měsícem

      Crazy tip!!

    • @trevor4664
      @trevor4664 Před měsícem

      Are you available for hire? I could use some help creating a good interactive foliage system

    • @ghislaingirardot
      @ghislaingirardot  Před měsícem

      @@trevor4664 me? nop

    • @trevor4664
      @trevor4664 Před měsícem

      @@ghislaingirardot no the guy who started the comment thread

  • @abdoulraoufgambo
    @abdoulraoufgambo Před měsícem

    Merci pour le bon contenu !

  • @JeckleCed
    @JeckleCed Před měsícem +1

    Au lieu de supprimer une instance et l'ajouter de nouveau plus tard, il est possible de passer une transform avec un scale de zéro ( via la fonction UpdateInstanceTransform )
    C'est une technique utilisé communement

    • @ghislaingirardot
      @ghislaingirardot  Před měsícem +1

      Ah ben oui je suis con! Je suggérais de faire ça dans le vertex shader mais on peut juste faire ça en effet xD

  • @sigxfs
    @sigxfs Před měsícem

    Amazing tutorial. Would you consider doing a tutorial for making an interactive snow material / system? I tried making one using parallax occlusion mapping and render targets but never got it fully working.

  • @evanlane1690
    @evanlane1690 Před měsícem

    Yesssssss

  • @kettenotter
    @kettenotter Před měsícem +3

    I had the same experience with lightweight instances! What a pain.
    But in theory they can do things which are very hard to do by yourself. If I remember correctly they will do some conversion under the hood if you trace against them they will get converted as soon as you acess the underlying actor. So the pointer will point to an actor which doesn't exist yet. Or was it on trace hit? No idea. And no idea if it actually works. But sounds pretty cool especially if you don't have to replace line trace code and such.

    • @ghislaingirardot
      @ghislaingirardot  Před měsícem +1

      Yup, I've seen something like that using a trace hit. But what if I don't want to do traces? :D Or maybe the way to go is to do a multi-capsules trace in place, at the current's character position, and check hit actors :shrug: I dunno, it felt soooo sketchy to use haha. I'm sure it'll improve though.

    • @Ziboo30
      @Ziboo30 Před měsícem

      @@ghislaingirardot I really don't think it would be unmanageable to make it work large scale. I'm not super familiar with FoliageInstanes, but I am with ISM and tracing + switching is pretty fast. What I would do instead of a BVH, is to simply chunk all instances into cells (volumes), so you wouldn't iterate over all of thems, but only the ones in cell the player is currently in. Sure it will be a little more drawcalls depending on your cell size, but would definitly be worth it :)
      In 5.4 if you can use PCG and enable runtime partition generation, it will chunk them automaticly based on the Grid Size you choose :)

    • @ghislaingirardot
      @ghislaingirardot  Před měsícem

      @@Ziboo30 Yup! The way I see it, there are two ways this could be scaled up: 1) to support a large world, in that case yeah there are solutions like you mentioned it. ISMC could be used to create a grid, like you said. You could also make your foliage have simple collision and rely on overlap events on your character to get the ISMC & instance index upon overlap, and let Chaos do the heavy work of partitionning/spatialization. Definitely doable! 2) to support a large 'simulation context', meaning, have many actors interacting with the foliage or a large scale simulation to support wind etc. In that case this technique is definitely not scalable.

  • @QuakeProBro
    @QuakeProBro Před měsícem

    I would love to see you implement this with the actor pooling you've mentioned. I might give it a shot aswell if I have the time. This could be like an automatic solution for limiting the amount of skeletal meshes you want to simulate at once, if there are multiple pawns interacting with foliage, since the system is dependant on the amount of pooled actors you have spawned in the beginning.
    We may need to implement prioritization around the player, since this is the area we want to see the effect all the time.
    And what about using two LODs of the skm, one with more bones and one super simplified with for example only the root bone, that is only used if another pawn in medium distance is interacting with the foliage? I have no idea if that would even be worth it regarding the extra work and the visual effect tho.

    • @ghislaingirardot
      @ghislaingirardot  Před měsícem +1

      Yup, doable. I did that at one point. The thing is, it adds quite a bit of nodes to implement the pooling thing, and even more so if you want to add a priority & LOD system, so because of the massive blueprint overhead, it can actually cost more to run that logic in BP than the performance gain it gives... In CPP that'd be a different story

    • @QuakeProBro
      @QuakeProBro Před měsícem

      Hmm yeah that makes sense.
      I thought of comparing player position & instance transform inside the foliage actor, if it’s over a certain threshold we notify either the LOD0 pool or the LOD1 pool via an interface, see wether there is a skeletal mesh available and place it. The interface only sends over the transform to the pool. But I guess we would also need to store indices to return the correct skm to the pool + looping through the pool array to either compare transforms, get a bool or int, whatever we use to determine if a skeletal mesh is available or not.
      That indeed feels a bit much compared to simply spawn & destroy 😅
      I‘ll test if this works for my project or not. I‘m still sad, that the lightweight instance system isn’t really working, since it sounds great on paper.
      Great video as always!

    • @ghislaingirardot
      @ghislaingirardot  Před měsícem +1

      @@QuakeProBro Yeah something like that would likely work. Pooling shouldn't too big of a hassle to implement tbh :) Good luck!

  • @nindyatisa2759
    @nindyatisa2759 Před 16 dny

    how i make variation plant interact foliage?

  • @tmdquentin5095
    @tmdquentin5095 Před měsícem

    Est-ce qu'il ne serait pas simplement possible de faire un capsule trace sur le tick ou sur un timer et de simplément convertir les objets qui sont dans le hit?

    • @ghislaingirardot
      @ghislaingirardot  Před měsícem +1

      Tout à fait possible. Il a été porté à mon attention que tu peux configurer les static foliage asset pour avoir une simple primitive de collision et utiliser un overlap event sur ton character pour récuperer les instances avec lesquelles tu dois interagir! Tu peux cast le hit actor to FoliageInstancedStaticMeshComponent et le OtherBodyIndex corresponds ducoup a l'index de l'instance! Bien mieux que ce que j'ai montré dans la vidéo :)

    • @tmdquentin5095
      @tmdquentin5095 Před měsícem +1

      @@ghislaingirardot exactement, quelque chose de la sorte. Je crois que le mieux serait d'utiliser une interface au lieu d'un cast.

  • @LyriaStudio
    @LyriaStudio Před měsícem

    Hum, et si on utilise le lightweight instance, qui permet de changer automatiquement un ISM en actor correspondant, ce serais pas plus pratique ?

    • @ghislaingirardot
      @ghislaingirardot  Před měsícem

      Il y a toute une partie de la vidéo qui est dédié à ce sujet 🤷

    • @LyriaStudio
      @LyriaStudio Před měsícem

      @@ghislaingirardot Mince, j'ai du looper, pourtant j'ai vue la vidéo entière 🤔

    • @ghislaingirardot
      @ghislaingirardot  Před měsícem

      @@LyriaStudio ben y a un chapitre LWI à 9:35 - Lightweight Instances :D

  • @perfectionist724
    @perfectionist724 Před 18 dny

    Could you tell me how you setup the root?
    I set mine to kinematic. No collision. No gravity.
    I always get an error from ue. Saying physics is not enabled.
    But it is.
    Thanks if you can help

    • @ghislaingirardot
      @ghislaingirardot  Před 18 dny

      That's likely unrelated to the bones/physics bodies. I'm sure it has to do with your skeletal component's collision settings

    • @perfectionist724
      @perfectionist724 Před 18 dny

      @ghislaingirardot ok thanks