Godot 4 C# Tutorial - Minecraft Terrain - Part 4 (Infinite Generation)

Ойындар

Get the source code on my Patreon: / xen42
Join my Discord server idk why not: / discord
Watch part 1 first: • Godot 4 C# Tutorial - ...
Was made in Godot version 4.2 (mono) with Visual Studio 2022
This video covers implementing infinitely generating terrain.
This is the second video in a tutorial series on how you can make editable voxel terrain with threaded chunk loading/unloading in Godot 4 using C#. This is an intermediate tutorial series that assumes you have working knowledge of C# and Godot, as well as LINQ.
You can also just blindly copy stuff down I can't tell you what to do I'm not your mom.
I want to be real and just call the video voxel terrain but KZread analytics tell me people search for "Godot Minecraft" and we just have to play the algorithm am I right, a man's gotta eat.

Пікірлер: 46

  • @fallencup9037
    @fallencup9037Ай бұрын

    Literally the best tutorial video out there, these stuff sounds complicated at first but you make it really easy to understand! Thank you for the guides

  • @xen-42

    @xen-42

    Ай бұрын

    Glad it was helpful!

  • @tumbleweb
    @tumbleweb8 ай бұрын

    Thanks for this series! Would like to implement a multiplayer version for funsies but didn't feel confident GDScript was up for the task. Would love to see how you tackle other complex projects in C#!

  • @xen-42

    @xen-42

    8 ай бұрын

    Glad you liked it! Maybe I'll do a multiplayer project that sounds fun

  • @StickDude11

    @StickDude11

    5 ай бұрын

    @@xen-42 I would love it if you implemented multiplayer into this project! I love this series and I would love for it to continue

  • @Novatailonpawz

    @Novatailonpawz

    5 ай бұрын

    @@xen-42multiplayer would be great

  • @CirculensProductions
    @CirculensProductions5 ай бұрын

    One of the best tutorial series ever

  • @mrdostuff204
    @mrdostuff2047 ай бұрын

    If you're unsure what to do next, you could implement chunk saving. Chunks currently reset when unloaded and reloaded (as you probably already know).

  • @xen-42

    @xen-42

    7 ай бұрын

    Yeah great idea, would be cool to see if I can get it to do that without running terribly

  • @HurricaneSA

    @HurricaneSA

    5 ай бұрын

    Store every newly generated chunk in a list or dictionary. Before unloading a chunk, update it in your chunk dictionary, with whatever modifications the player made added in. When loading up the chunk again, load it from the list or dictionary of chunks instead of regenerating it. And that's basically all there is to chunk saving.

  • @fiftybytes
    @fiftybytes4 ай бұрын

    great series! one thing, i'd highly recommend making a new thread for the Generate() and Update() functions, it highly improves performance when loading in chunks, breaking blocks and placing blocks.

  • @GuildOfCalamity
    @GuildOfCalamity7 ай бұрын

    Great video. I usually never type "private" since all variables/methods are private by default; you can save yourself some extra typing.

  • @xen-42

    @xen-42

    7 ай бұрын

    Fair point, I guess I just like seeing it explicitly written

  • @GuildOfCalamity

    @GuildOfCalamity

    7 ай бұрын

    @@xen-42 Yeah, it took me a long time to break the habit... but you'll thank me a year from now when your fingers don't seize up.

  • @HurricaneSA

    @HurricaneSA

    5 ай бұрын

    @@GuildOfCalamity Typing "pr" and pressing Tab to get "private" is not that much typing and you might not always work with compilers or languages that allows you to omit explicit scoping. It's neither here no there but yeah, explicit scoping is a good habit anyway.

  • @Syvies
    @Syvies4 ай бұрын

    Great tutorial, I managed to follow it by using only GDScript, had to look up some things about Godot's Thread, but else, it works really good. It would be interesting to see saving and loading chunks and maybe with it the ability to save a world! I saw that you talk about doing it, but as you haven't done it yet I guess it's ending up more complex than anticipated ?

  • @xen-42

    @xen-42

    4 ай бұрын

    Glad it was useful! I just haven't gone back to the project since I've been working on other games, but whenever I do go back to working on a Minecraft clone I'll be sure to do the tutorial too. Just don't know when that is gonna be yet

  • @meezi2987
    @meezi29878 ай бұрын

    good video I am waiting for next

  • @xen-42

    @xen-42

    8 ай бұрын

    This was the last one I've made for now. Do you have any suggestions for what tutorials I do next?

  • @meezi2987

    @meezi2987

    8 ай бұрын

    you can make a professional tutorial about gdscript because aren't any big tutorial about it on KZread

  • @LeHamsterRuso
    @LeHamsterRuso2 ай бұрын

    Thanks for theses videos :-)

  • @xen-42

    @xen-42

    2 ай бұрын

    I'm glad it was helpful!

  • @LeHamsterRuso

    @LeHamsterRuso

    2 ай бұрын

    @@xen-42 very very very helpul. My daughter asked me to make some sort of mix between Animal Crossing and Minecraft and I'm using your engine in order to begin the prototype.

  • @lesca6461
    @lesca64617 ай бұрын

    Awesome job, you deserve more support for your effort. Is it possible to replace the chunks for height maps? It might load faster, if I am not mistaken.

  • @xen-42

    @xen-42

    7 ай бұрын

    Thank you! Do you mean using a heightmap instead of randomly generating it? Could be faster yeah.

  • @fiftybytes
    @fiftybytes4 ай бұрын

    i'd love to see chunk saving/loading, so changes to a chunk are saved even when unloaded

  • @sirgrem2988
    @sirgrem29883 ай бұрын

    This has been quite a joy and suffering for Godot Mono. It kept crashing for some unimaginable reason, and I have no idea why. At least it's not that frequent, however.

  • @vibingLieke
    @vibingLieke6 ай бұрын

    Awesome tutorial, thank you so much for sharing! Are you considering adding more to it?

  • @xen-42

    @xen-42

    6 ай бұрын

    Yes I hope to eventually! I think next I'd do some stuff on different types of terrain generation.

  • @vibingLieke

    @vibingLieke

    6 ай бұрын

    oh awesome, will definitely be checking that out then :)@@xen-42

  • @valgrann
    @valgrann5 ай бұрын

    Hello! I have a question, you are calling SetChunkPosition from the thread function with call_deferred(). call_deferred() sends the execution of the callable to the main thread, so SetChunkPosition is not being executed in the sub-thread, but rather in the main thread? Or it works differently in C#?

  • @xen-42

    @xen-42

    5 ай бұрын

    Yes it makes it get called in the main thread! Anything that directly affects a node like changing its position has to be done in the main thread (else Godot logs errors), so deferring it is a way to do that

  • @valgrann

    @valgrann

    5 ай бұрын

    @@xen-42 but this way isn't the heaviest logic (specially the generate() and update() methods) going to be executed in the main thread? it almost ends up being the same as making the chunk system single threaded. I followed your series but it didn't work for me since I ported it to GDScript, which is slower than C#. Every time I move from chunk to chunk my program hangs until the chunks are fully updated since everything is calculated in the main thread after all! I saw in the docs that manipulating nodes from sub-threads is perfectly safe as long as the node does not belong to /root/. So what I did was: 1. In my chunk manager I created a node instance which will be in memory but not inside the scene tree, Let's call it the "outer node". 2. In the chunk manager process function, I set the chunk's new position when the player moves (without calling generate() and update()), then I remove it from the scene tree and add it as a child of the outer node. 3. My sub-thread iterates through the outer node's children, calling their generate() and update() function directly, which works without call_deferred() since everything happens outside the active scene tree. 4. The sub-thread removes the chunk from the outer node and, using call_deferred, adds it back to the scene tree. This way I managed to manipulate the chunk from the sub-thread without using call_deferred()! Still needs improvements, though.

  • @HurricaneSA

    @HurricaneSA

    5 ай бұрын

    @@valgrann This is why one should always split the data calculations from the actual mesh building. This is not only true for Godot but basically any framework. Things like creating meshes can usually only be done in the main thread while data calculations can be done in multiple threads. So, you want to create separate methods for building arrays, lists and so on and then you run those methods on a different thread. Once the data is ready you defer back to the main thread to call the mesh building method and pass the data to that method.

  • @Rambley15
    @Rambley15Ай бұрын

    There is a way to do this using Godot's own script, and why am I doing this on my cell phone and this script you are using, it is not available for cell phones only from Godot itself

  • @HurricaneSA
    @HurricaneSA5 ай бұрын

    Maybe more optimized way to do this would be to simply fire off an event when the player is a certain distance from the edge of a chunk before calling the chunk update method, don't you think? That way there's no need to infinitely update chunks all the time. I think.

  • @xen-42

    @xen-42

    5 ай бұрын

    Wdym by infinitely updating all the time? They should only be being updated when their positions change, or when a block is changed in that chunk. Unless I messed something up somewhere.

  • @HurricaneSA

    @HurricaneSA

    5 ай бұрын

    @@xen-42 Isn't the ThreadProcess() method constantly checking the player position and updating accordingly? It seems that way to my coffee deprived brain anyway. If this is not the case then just ignore my comment.

  • @Butab
    @Butab6 ай бұрын

    Hey! Can you make same tutorial but on Godot 3.5.2 gdscript (I mean "How To Make Minecraft Terrain in Godot 3 in 45 Minutes" part 2)

  • @xen-42

    @xen-42

    6 ай бұрын

    Currently I dont plan on doing any more gdscript tutorials since I'm super out of practice with the language and much prefer C#, sorry!

  • @thepirateswirled
    @thepirateswirled4 ай бұрын

    GDScript or C#, what would you suggest now?

  • @xen-42

    @xen-42

    4 ай бұрын

    It's personal preference, I'm still 100% for C# though

  • @TeslaEdison23
    @TeslaEdison237 ай бұрын

    Hello, you can do the same tutorial but in gdscricp

  • @xen-42

    @xen-42

    7 ай бұрын

    A few people have asked me and honestly I probably won't do it, since I don't enjoy using gdscript anymore since switching to C#. I have a gdscript tutorial for Godot 3 from like 2 years ago and the reason it took so long for me to make this one was because I kept trying to redo it in gdscript and kept giving up since I'm much more used to c#.

  • @MikelMonleon

    @MikelMonleon

    6 ай бұрын

    Is there a place where you got stuck? I've been trying to get this working in gdscript for days. Cannot get the godot 3 version to work in godot 4@@xen-42

Келесі