Rust and Unity game development

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

This has to be the most cursed project I've ever done.

Here is the source code: https://github.com/TanTanDev/runity

πŸ‘οΈŽ︎ 20 πŸ‘€οΈŽ︎ u/TantanDev πŸ“…οΈŽ︎ Dec 15 2021 πŸ—«︎ replies

Been following your stuff for a bit & it’s super high qual - keep it up bro

πŸ‘οΈŽ︎ 8 πŸ‘€οΈŽ︎ u/Chip213 πŸ“…οΈŽ︎ Dec 15 2021 πŸ—«︎ replies

Tantan's Here?! Sick!!!

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/ikec4937 πŸ“…οΈŽ︎ Dec 16 2021 πŸ—«︎ replies

This is both so cursed and extremely entertaining! Thanks a lot for this! Taking mad science to the next level

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/elmowilk πŸ“…οΈŽ︎ Dec 15 2021 πŸ—«︎ replies
Captions
so here's a small unity project i made but it is kind of cursed because all of the gameplay code is 100 written in rust my favorite programming language i set out to figure out is there any chance unity and rust can work together and i found the answer this is a bad idea today i almost exclusively used the rust programmer language to make video games but i still miss some things from the unity game engine it has so many great tools the editor is phenomenal but the reason i was willing to jump the unity ship and use thrust so much these past two years was simply that using unity in c-sharp i felt like i wasn't growing as a programmer i felt like i was doing the same thing over and over and the code i wrote started becoming unnecessarily complex now i am super happy that i decided to learn rust because my programming skills have grown so much since then but i still miss having an editor like unity so as an experiment i wanted to see if it's possible to use rust and unity even though unity has no support for this programming language at all this is where my journey started i came across this video of someone utilizing rust within unity to generate meshes in these 15 minutes he thoroughly explains how it all works and to my surprise the basics are pretty simple ok we got this rust function called getnumber it returns the number seven to call this function from c-sharp we need to create a replica of the function the name the return type and the arguments needs to be exactly the same in c-sharp as in rust let's see if it works and oh yes it works ah perfectly was easier than i thought okay let's tell unity to move a transform from rust that should be easy i made a game object replica and rust i made a transform replica the game objects are iterated okay this is a mess i was trying to replicate the exact way unity did things and that just didn't work that well for some reason i mean yeah the code worked i was able to do this from rust the problem i had was this code was really hard to expand on this first attempt was a complete spaghetti mess and part of that may be because writing ffi code is very new to me anyway i trashed all of this code to get a clean state but with the knowledge of this previous attempt and then i remembered bevy is a thing if you don't know bevi is an entity component based game framework it is hands down one of the cleanest entity component system libraries i've ever come across now bevi is a game framework meaning it has windowing 3d rendering 2d rendering we don't need those things we're using unity for that but luckily bavi is built in such a modular way that we can extract out specific parts we want to use aka we only want to use the entity component system from bevi i have no idea if bevy will work well all i know is i like the entity component system if we could use that inside unity that would be bad so i had to try it something new i wanted to try was to utilize two dlls instead of one the code that communicates back and forth between c-sharp and rust is not very aesthetic i would prefer if we could hide the code that is gluing everything together from the gameplay code now here's where things get interesting let's examine how a game object is spawned from rust into unity step by step when the game starts the player is spawned from rust this is how we spawn entities in bevy we simply say spawn and any insert call after that will insert the components we're passing in we got a transform collision processing and this is a tag that allows us to differentiate player entities from other entities now this prefab component has one thing only and that is the name of the prefab we want to spawn now this prefab name will later be synced into unity and unity can then spawn this prefab there's one problem though how does unity map a string to a prefab you can't do that not that i'm aware of my solution was pretty simple in unity i have descriptible objects and i can simply map a string to a prefab so when ross tells unity hey spawn the prefab called player this scriptable object will then find the prefab based on the name if we go back to this spawn function from rust this is a part of bevy and bevy doesn't know how to communicate to c sharp so when does rust tell unity to spawn this prefab utilizing systems that are completely hidden to the gameplay programmer i have made this system that can react when an entity is spawned with a prefab component this is the part why bevy is so magical here's the code that tells unity to spawn a prefab my code is simply stating i want the entities that contains these specific components under these conditions and bevious magically figures out how to provide that to us anyway if bevy finds a newly created prefab entity this code will then communicate back to c-sharp with this prefab name now there's a lot of confusing string manipulation i'm doing here to be able to pass this rust string into c sharp it is not very pretty i know that's the short explanation how this works here is the full explanation but summarized very quickly how easy was that to follow along probably not at all but it really shows how many hoops i've had to jump through to get this to work man there's so many weird things i've had to do one example is logging when dealing with foreign function interfacing aka communicating between different languages there's a good chance in producing memory leaks or undefined behavior resulting in these lovely crashes now i don't think i can debug my rust code so i've had to resort to logging the problem is when i write printline in rust where where does it go i don't know so to get my logging messages from rust into unity i added this callback function so we can communicate back and forth doing all of this fancy stuff i showed previously so this is how we log stuff into unity i know it's horrible the code is so scary i prefer if we could write log messages something like this luckily the log library exists and this function we can hide in the implementation every time we type info warn or error this will be called hidden away if that sounds like a duct tape solution you just wait with all of that done runity can now tell unity to log stuff but what about game i had to make two separate logging implementations the game logger communicates with brunetti the unity logger communicates with c-sharp why why why oh man this is just some small examples of the really painful programming things i had to do to get this to work if you appreciate the effort i've gone through to try to make this a reality please leave a like and subscribe okay what is it actually like to write a game using rust and unity how i built this back end is totally different how you make a game with this back end so let's make a tiny game right now let's see what it's like to use [Music] here's our starting program and we all we do is print it works so after building it we then take our dll file and just drop it into our project all right let's add runity right here rooney timono and then the name of the dll runity demo i don't think we need to assign this right now let's just run it what will happen let's ignore that it works that is incredible okay let's make the scriptable object also ruin it descriptible prefabs and let's just assign that and get away from the error and it crashed why what did i do as you can see everything works perfectly i fixed the crash data banana and the monkey i know to the listed descriptable objects so we can spawn this prefabs from rust the monkey and banana bomb we have the game kind of let's spawn some more bananas tapping space okay i actually have no idea what i'm doing but i don't know let's make them move around with the gravity [Music] and let's add some monkey movements and just like that we have remade donkey kong get kong with unity and rust incredible as you can see we're just fighting regular bevy code i really like bevi's entity component system let me show you some examples on things we can do with this small project we made let's say we want the bananas to spawn from the monkey's position well we can query all of the entities with a monkey tag and from this query we can get the position of the monkey and spawn the banana from that position what's cool about this is if we spawn another monkey well the banana then spawns from that one too what if the banana had the monkey controller we're just adding that component to it and bam the banana also moves with the user inputs ah i like bevy it's so modular it's so nice it's so nice now i don't think i will expand much on this project i wanted to see is it possible to use rust and unity turns out it is but it is just as hard as i thought it would be okay here is the deal with unity runity has an enormous amount of things that needs to be fixed if you would ever consider actually making a game with this starting with the lackluster features of runity there are only six features when i talk about features i mean things like spawning prefabs destroying prefabs modifying your transform but with just these 6 things i was still able to make a small game with rust and unity now if the feature list isn't lackluster enough here's a list of issues that needs to be addressed with unity sitting down going through the code i identified seven issues with the runity this needs to be addressed in order to improve the design of the code but most importantly the performance i've spent quite a lot of time on this project and i want to get this video out which is why i'm releasing it in its current state the source code is public if you want to see how all of this works go ahead i don't actually expect anyone to actually try it out because it isn't that developed the scope of this project is truly huge if you enjoy rust as much as i do i would recommend sticking with bevy as it is instead of using unity and bevy please help the algorithm out by leaving a like subscribe we're closing in on 10 000 subscribers and honestly that is insane can we reach that before 2022 yeah yeah let's try it let's try this has been tandem bye-bye [Music] you
Info
Channel: Tantan
Views: 3,916
Rating: undefined out of 5
Keywords: rust, rustlang, unity, gamedev, ffi, rust and unity, tantan, rustacean, bevy, game development
Id: L7M_vbo1N2g
Channel Id: undefined
Length: 11min 44sec (704 seconds)
Published: Wed Dec 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.