Godot 4 & Rust - Getting Started

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back to another tutorial today we are looking into the rust bindings for the go. 4 engine therefore we will create a small project let's start first we open the finder and create a new folder next let's open the folder in our edit of choice in my case it's codium then we will create a new rust Library let's call the library also rust you can name it however you like um then following up we are changing to the cargo tber file and add the crate type which will be which needs to be defined based on your operating system and of course the way how the library should be created so for example I'm using a Mech so therefore on the mech I can use Dynamic libraries in case of iOS or the iPad I would need aesthetic Library so therefore I add both types there next we are adding the go do dependency so that we have the crate or the library um available for the use therefore we are heading back to the GDX um GitHub repository and copy and paste the URL here in addition we add the branch um which is referencing to the master now we can change to the lip RS file remove the whole content and start finally initializing our new library what we want to create in order to do that you need to import the go dot specific um Imports I use the Prelude to have the standard inputs ready then adding a new struct which is actually the rust extension or Library however you like to call it and that one will now have a unsafe implementation for the um extension Library which is the main entry point which will be used for the whole uh codot implementation and referencing it's an unsafe implementation so therefore we need to add the unsafe and we also Mark the the macro with the go do extension then following up we can actually start implementing a new component in that case the player RS and we import the module in the lip RS folder the player RS is just a simple um struct for now where we want to make a texture animating by rotating it the base um component is a requirement in that case so that we have a reference to the node which will be generated um on the go doite later therefore we ensure all the inputs are met and extend the player properly with a uh derive uh go. class and also with the following up um class definition of the ice Sprite but more to that very soon so now we added the go do class so that it gets visible um and in addition we also declare what kind of class is the base class of our our new defined struct in that case it's the ice Sprite 2D please note that all the relevant um classes from go do are referenced with I as the next step we start the implementation for the player component so we will implement the initialized method and on the other hand the physic process which should get called by each frame um to rotate this Sprite at the end Esty signature in the arguments of the init function look looks quite a bit strange for the parameter we just can directly replace it with the base and right Tod as declared in line number seven now we need to ensure that it gets exposed to go do so therefore we add the mro go. API and Mark it with that one and now let's implement the logic in order to rotate our future Sprite therefore we use self and base mutation because we want to change the base component um value in that case the rotation please note that you should not reference directly the base property instead use the proper functions in that case for mutation we use basore mute bracket and if you just want to read values just use base brackets to verify our implementation let's quickly build it everything went through and looks good so far now let's heading back to the go. editor and let's first let's create a new project and select the parent folder where where you want to store this project so it should be next to the rust folder actually let's hit the create folder button ensure the renderer is also matching your requirements in my case I just use a the renderer type mobile and then create it next let's select a scene in that case a 2d for example scene um as we're just moving a Sprite and then just give it a a proper name in my case I just call it main scene and then I hit command s to save actually the new scene and let's quickly run the example here to select also the proper setup of the default scene when running the project once done um we can go back as you see to visual studio or codium and create a new file called rust GD extension which is actually the configuration to let go. know about our library so the file contains um two properties or let's say base entries the configuration and the libraries libraries in that case are referring to the platform specific builds what we just did now with cargo build and therefore we need to pass in the proper U pths otherwise the libraries will not be visible um and cannot be bundled during the compilation with the go do engine when exporting your project for example then just add the reference to it ensure that you have res um colum SL slash um in front of it because otherwise your references will not be found and every build will unfortunately not work properly please also note that I have a M1 um Mech so that means Intel mechs of course need to refer to the X um 86 um builds instead of the M 64 and then the compatibility minimum is set in my scenario now to 4.1 and we also need to create a entry symbol which is by default the GDX rust init you can also name it differently but I just picked it based on the documentation as well from the GD extension in Rust heading back to the go do editor we can double click the r. extension and see that for some reason the files or libraries are not found therefore let's check our project and let's open the target folder and look into it as you can see here we don't have this um Dynamic libraries or static libraries created even when we hit cargo build the libraries are not there so most likely with with our cargo configuration is something wrong in more particular the crate type might be missing of something and yes we were actually missing the brackets with the lip specification otherwise it's a rust library and the C library won't recognize it um after hitting that one it seems to work finally and we have our Dynamic Li libraries available when pressing again the rust go do extension you also notice in the right side of the editor that there was a change in the UI and therefore that's kind of a sign that we can now reference our player as you can see by adding a new note um we are able now to add it let's then just add the new texture what we want to use for the player resis it and actually then just hit and run and see if our whole things are working don't forget to save of course and here we are our Sprite is rotating I hope you enjoyed the session see you next time thank you
Info
Channel: schr3da
Views: 1,074
Rating: undefined out of 5
Keywords: Godot Engine, Godot Engine & Rust, Godot Engine and Rust Programming Language, Godot & Rust, Godot & Rust Programming, Godot, Gdextension
Id: G9UDVtR5AYA
Channel Id: undefined
Length: 11min 6sec (666 seconds)
Published: Thu Jan 25 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.