EASY Wave Function Collapse Tutorial for Unity Games! [Unity Tutorial - Reupload]

Sdílet
Vložit
  • čas přidán 8. 08. 2023
  • Hey! I have reuploaded this video without the audio as a lot of people commented about it in the older video. Both versions are still available and there's no content differences with them - but this version might be easier for some people to listen to! Thank you :)
    This video is a quick overview of the Wave Function Collapse algorithm and how we can apply it inside of our very own Unity Project!
    The code for the video can be found here: github.com/GarnetKane99/WaveF...

Komentáře • 21

  • @Neil_09
    @Neil_09 Před 7 měsíci

    Saving this video. Tnx man

  • @hamsterbyte
    @hamsterbyte Před 8 měsíci

    This is a pretty simple implementation. Good on you for making this algorithm more accessible to new developers! I'm dubious though, it seems like there are a lot of inefficiencies in the code. I'm not going to point out everything I would have done differently, this works absolutely fine. However, I am curious if you did any performance tests for how long it actually takes to generate a map with your code? Like, is it viable to do this on the fly for infinite world generation, or is it something that would require a loading screen? If it needs a loading screen that is fine too, it's just something that is worth noting if someone is going to try and implement this in a project. Cheers!

    • @GarnetKane
      @GarnetKane  Před 8 měsíci +1

      Appreciate it! And you're completely right - this code is in by no means efficient, but is definitely to get people better introduced into the algorithm as a whole.
      There's a whole bunch that I definitely encourage people to look into with optimising this algorithm - I didn't look into it myself with efficiency and performance, but realistically, it all depends on the scale of the project - I think infinite world generation with like block chunk loading and stuff would definitely be where it gets pricey, but for a small scale 2d dungeon crawler style shouldn't pose an issue at all.

    • @Und3rpr3ssur3_Gaming
      @Und3rpr3ssur3_Gaming Před 6 měsíci

      @@GarnetKane Hello, is it possible by any chance to acquire a sense of direction of where to look when it comes to optimizing this algorithm? I'm attempting to do that infinite world generation stuff and it indeed gets performance-intensive slowing things down way too much. I've tried doing little things here and there but overall I haven't gotten very far with it. Being guided to the right sources to overcome this hurdle would be greatly appreciated.

  • @homersimpson4532
    @homersimpson4532 Před 9 měsíci

    You can replace most of the entropy function with a much simpler implementation:
    tempGrid.RemoveAll(c => c.GetCollapse());
    tempGrid.Sort((a, b) => { return a.GetTileOptions().Length - b.GetTileOptions().Length; });
    tempGrid.RemoveAll(x => x.GetTileOptions().Length != tempGrid[0].GetTileOptions().Length);

  • @EagleTopGaming
    @EagleTopGaming Před 3 měsíci +1

    If I understand this right it does not actually work as implied. It seems to propagate the changes by just working its way through the index systematically from one corner then in rows all the way down. It is not going to propagate from the collapsed tile out. Is that correct? Though I may just be reading the code wrong. [I do not use C# much.]
    Thanks a ton for the video. This has been the first WFC tutorial simple and thorough enough that I was able follow and recreate a working version of what you explained.

    • @GarnetKane
      @GarnetKane  Před 3 měsíci

      You're actually completely right in this - my implementation (even being not as well optimised) does actually miss out on the proper propagation, but it's definitely a good start for how the algorithm should work! Glad you enjoyed it though!

  • @M1idget
    @M1idget Před 3 měsíci

    what kind of algorithm do you prefer for 3D hexagonal map

  • @ray17506
    @ray17506 Před 6 měsíci +1

    How do you convert this with the Y axis flipped? I tried converting this in Godot but it screws everything up. I tried just inverting (y + 1 instead of y - 1 for up etc) but it gives srtange results.

    • @GarnetKane
      @GarnetKane  Před 6 měsíci +1

      Ooh. interesting - maybe just inverting the y’s in the original equations (i.e. ‘y + 1’ becomes ‘-y + 1’) etc.
      Let me know how that goes! best of luck

    • @ray17506
      @ray17506 Před 6 měsíci +1

      @@GarnetKane Yeah i figured it out as soon as I noticed you replied. Did what you recommended interestingly enough. It took me a whole day trying to figure out what was going on. Im a huge noob in game dev. It really helps that youre code was simple enough to work with that I could convert it.
      Your wave function example was the only one I could find that was readable to me. All the godot vids I found used plugins. I wanted to code it myself like you did cause I wanted to learn. Thanks again for what you do!

  • @arataryan6188
    @arataryan6188 Před 7 měsíci

    what will happen if current cell does not have neighbour but there are some cell that not collapsed? (i try to make on my own)

    • @EagleTopGaming
      @EagleTopGaming Před 3 měsíci

      How could the current cell not have neighbors?

    • @arataryan6188
      @arataryan6188 Před 3 měsíci

      @@EagleTopGamingsorry, it actually my mistake. is all working now

    • @EagleTopGaming
      @EagleTopGaming Před 3 měsíci

      Nice! Well done 😊@@arataryan6188

  • @ReservedLaughter
    @ReservedLaughter Před 8 měsíci +2

    3d PLEASE

  • @andreaaliberti9349
    @andreaaliberti9349 Před 8 měsíci +1

    Would it be possible to add all the possibilities for connection on a config file? To not set the possible neighbour from Unity but from the code.

    • @GarnetKane
      @GarnetKane  Před 8 měsíci +2

      Most definitely! I haven't implemented it specifically, but in the Wave Function Collapse algorithm, you can make it colour-based and programmatically assign neighbours based on corresponding edges -
      I somewhat went over it in the video at around the 3m20s mark, but to be more in depth, you can assort each edge into 3 segments (or more depending on how complicated the tiles are).
      Imagine "Tile A" - the top left is white, top middle is pink and top right is black. For each colour you can assign a number, so Tile A North would be [0,1,2] where 0 always corresponds to white, 1 always corresponds to pink and 2 always corresponds to black.
      When assigning neighbours, what you would do instead is find any tile that has a Bottom piece of [0,1,2] to match - and this can all be predefined inside of a config file or object addressable or json file, whatever is convenient for you!
      Definitely more complex, but this is the gist of the idea - hope it helps!

    • @andreaaliberti9349
      @andreaaliberti9349 Před 8 měsíci

      @@GarnetKane thank you! Nice work bro👍

  • @carltonamarion5978
    @carltonamarion5978 Před 10 měsíci +1

    Promo_SM 🏃