9 ms·
Unreal Rust
- pornel 4y agoThis is great, because Unreal is a C++ project that's not so easy to just Rewrite In Rust. It's also nice it uses bevy's ECS. It's made to fit Rust's type system and borrow checking model, and is highly parallel. It's really awesome how easy it is to distribute work across cores with it, without risk of heisenbugs thanks to Rust's data-race-safety guarantees. I know game development sees traditional software best practices as not applicable to them, but then games struggle with showstopping bugs and single-core performance bottlenecks. I hope someone will bet that Rust, despite being stricter and seemingly slower to iterate with, can be a net benefit from lower defect rates. Rust users outside of game dev praise the "if it compiles, it's usually correct", and that junior devs can be told not to write unsafe code, so they can't cause UB and memory corruption.
- waboremo 4y agoWhy would you think that? All of the game developers I've met don't really view themselves as separate from traditional software best practices, just that there's a lot more involved in making a game than people are ever really aware of. They're also among some of the most talented programmers, the stuff they have to come up with is insanity sometimes, so it's certainly not about them not caring about best practices. Games aren't struggling because they're written in Unreal's flavor of C++ (or whatever other currently existing engines and their respective languages), there are insane deadlines always being pushed. There is never enough time and never enough money. Neither of these problems are solved with Rust, at least not to a substantial degree.
- Ygg2 4y ago> there are insane deadlines always being pushed. Higher compilations times aren't all bad https://xkcd.com/303/ https://xkcd.com/303/
- t8sr 4y agoWhy do specifically Rust programmers think that people in every domain are just misguided and waiting for someone to teach them the right development practices? The sheer hubris… The kind of bugs that games mostly struggle with these days have nothing to do with the stuff Rust is targeting, like memory safety. They are “business logic” problems with many interacting systems resulting in unpredictable behavior, buggy level geometry, or poorly scripted missions not accounting for all player behavior. How exactly does Rust help with any of that?
- nynx 4y agoI mean, dude, I’ve seen the C++ written by organizations with supposedly highly-competent programmers. I think maybe we should let programmers get a little help from language designers.
- steveklabnik 4y agoMemory safety does matter for games. Especially in places like networked games, or anti cheat software. Even in single player games, a game crashing and losing your progress sucks. Rust’s non-borrow checker features help with other kinds of things. Rust isn’t only an ownership system.
- MiguelX413 4y agoAs mentioned, the type system helps reduce invalid states among many other things too!
- moldavi 4y agoFor a single player turn-based game, I'm not so sure the tradeoff is as obvious as everyone says, after coding one in C++ and another in Rust. It's turn based, so I don't need AAA game multi-threaded performance. It's single-player, so cheating doesn't really hurt anyone. I use sanitizers to catch memory problems, but there have only been a few of those over the years. Maybe ECS just isn't that vulnerable to memory-safety problems? The borrow checker prevents iterator invalidation problems, but most of my functions are read-only so there's not really a chance for those anyway, or many other single-threaded race conditions for that matter. After this long using Rust, I'm noticing more and more that the borrow checker is imposing a lot of artificial complexity, when I compare it to my C++ version. We're often told that Rust is hard because the underlying problem is hard, but I've encountered many cases where that's not true, it really is just the borrow checker. And unfortunately, most of them are problems that Polonius won't fix. Rust has a lot of great features (enums and cargo!) but I think one should think carefully about their domain and architecture before choosing a language, lest they pay too much cost for too little benefit. Just my two cents!
- capableweb 4y ago> Rust users outside of game dev praise the "if it compiles, it's usually correct", Why do people keep echoing this sentiment? I don't find this to be particularly true, in my sense of "correct". Yes, it does what the code says it'll do, but rarely the problem I actually get stuck at are language/syntax/semantic errors, it's usually domain/logic errors. Same can be said for PHP, JavaScript and a bunch of languages, as every program that is possible to run without error, is correct, at least in the eyes of the interpreter. But again, the difficult errors are not syntax/language errors.
- FpUser 4y ago>"but rarely the problem I actually get stuck at are language/syntax/semantic errors, it's usually domain/logic errors." Exactly my case. I've forgotten last time I've had memory alloc / free/ overrun /free after use etc. related bug in my C++ projects. I am using modern C++ which in combination with STL containers makes me forget about all this C++ is scary FUD. I am however not being "turn everything into template" maniac and in general trying for code not to be fancy but rather readable.
- patrick451 4y agoYeah, it's such as silly sentiment, which honestly makes me wonder about the skill of the programmers repeating it. Exactly none of the bugs I've fixed in the last month had anything to do with memory corruption or data races or other undefined behavior.
- Yoric 4y agoIt feels like something was misquoted at some point. The main benefit of Rust towards safety is not memory safety or data race safety or undefined behavior. The main benefit of Rust towards safety is a strong type system with affine typing. When used properly, this eliminates huge classes of bugs. Most of the bugs that I need to fight when I'm writing in Python or JS, for instance, are simply impossible in Rust. Of course, when I'm writing C++ (which I don't do a lot these days), I really miss all the features that you mentioned.
- virtualritz 4y ago
- Animats 4y agoThis is great, because Unreal is a C++ project that's not so easy to just Rewrite In Rust. True. Although rewriting Nanite in Rust would be useful. Nanite is a very clever data structure for meshes. It's brittle, and full of internal relative addresses within the data item, so it's very vulnerable to buffer overflows. If it becomes widely used outside of UE, it might become something that gets supported in GPU hardware.
- RcouF1uZ4gsC 4y ago> It's brittle, and full of internal relative addresses within the data item, I am not sure how much you would gain by doing this. Internal references are one of the things where it is very hard to express in safe Rust what you want to do (see doubly linked lists and graphs). You can get around that by using vectors and indexes, but that is bypassing the borrow checker, and with it, much of your safety and mutability checks.
- amelius 4y agoYes, Rust is great for tree-like data structures. However, add one non-tree edge to your graph and you're in big trouble. This demonstrates the flexibility of GC'd languages, where you don't paint yourself into a corner so easily.
- Animats 4y agoYes, Rust is great for tree-like data structures. However, add one non-tree edge to your graph and you're in big trouble. Good summary. Most of the headaches I have in Rust come from needing something that's not a simple tree. Parts that are simple trees are really easy. Nanite is a DAG, by the way. The whole point of Nanite is that instances are combined, recursively. A mile of chain link fence would be highly detailed sections of wire, combined into full wires, combined into fence panels... But not just all simple repeats. If there's a hole in the fence somewhere, that can be represented.
- stouset 4y agoI really don’t get this perspective. People act like you need one self-referential struct and suddenly you’ve gotta switch languages. Just use unsafe! That’s what it’s there for. You can use internally-unsafe semantics to expose an externally-safe API and nobody needs to care. You get the Rust’s safety benefits everywhere else (not to mention all the other nice parts) and your unsafe code is limited only to the areas it’s truly necessary.
- Kukumber 4y agoWill it improve iteration time in Unreal? Because C++ already is way too slow to compile wich hurts iteration time, wich is why most people fall back to plain simple blueprints, and even that can become quite heavy Epic is working on a new scripting language that will improve this What Rust brings to game development and how it's better than C/C++ in that regard? Because you don't develop a game the same way, with the same constraints as a driver for example
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- forrestthewoods 4y agoIs it? With live coding how long do your compiles take? TBH Unreal C++ is faster to compile than Unity C#. It is slower than an interpreted language. But I’ve also worked pipelines that chain Python executions which compound into ~5 second boot time. Faster is always better of course. But I often think people overstate compile times. The upside is it means people work hard to improve things from good to great!
- Kukumber 4y agoUnity is not a good benchmark, it's becoming slower every year Hot reload is great for small edits, but anything that require substantial changes or refactors and you got to recompile everything, that's what's slow
- forrestthewoods 4y agoHow slow? My Unreal C++ modules are pretty small. But on a P620 I’d say my time from editor -> compile -> relaunch editor in under a minute? I think I can compile and link the full engine in 15 minutes? But I will admit my current Unreal projects are quite small.
- geenat 4y agoAlso excited about the Python dialect coming to Unreal, which should have a major effect on iteration time.
- dagmx 4y agoCould you elaborate on Python dialect? Unreal already supports full Python for some stuff. They do also have a language called Verse in the works but I don’t believe that it has any relationship to Python
- ClimaxGravely 4y agoLast I checked, python support is editor-only. I believe Verse is made by a small team who previously worked on a game-specific scripting language called Skookum script. I used it maybe a decade ago so my memory is hazy but I think you are correct, it didn't necessarily have much relation to Python. I remember it having some unique game-specific async constructs. I'm certainly looking forward to trying it out!
- scns 4y agoSimon Peyton Jones is working on Verse. https://discourse.haskell.org/t/an-epic-future-for-spj/3573 https://discourse.haskell.org/t/an-epic-future-for-spj/3573
- ClimaxGravely 4y agoOh wow I had no idea he had joined Epic. I'm looking forward to seeing what Verse ends up becoming.
- ferrumfist 4y agoThere is a github project that allows runtime Python scripting. I've tried it and it does work, however I tested it on UE4 and not UE5. https://github.com/20tab/UnrealEnginePython https://github.com/20tab/UnrealEnginePython
- forrestthewoods 4y agoNeat! I write a lot of C++ plugins that are used in both Unreal and Unity. I like to think of them as "side loading". They can do whatever they want, however they want. The API surface that interacts with either engine is pretty minimal. I think "use Unreal as a renderer" is underrated. You could imagine writing your full simulation logic independent of the AActor framework and then using Unreal just for rendering. For a client/server game the server might not use Unreal at all! I'm not sure how valuable it is to use Rust but also use Unreal's framework and blueprints. Bevy + Unreal is a pretty fascinating combo and how much lifting is done by each side can be done in lots of ways.
- vardump 4y agoI was almost certain this would be about running Rust under DOS unreal mode, flat 32-bit address space in real mode. https://en.wikipedia.org/wiki/Unreal_mode https://en.wikipedia.org/wiki/Unreal_mode
- deleted 4y ago[deleted]
- hertzrat 4y agoThese discussions always remind me of some talks by Jonathan blow where he argues rust doesn’t solve the hard problems he needed it to. There are podcast episodes with better discussions, but the main one people link to seems to be this I haven’t used rust, but I sympathize with his problems with pointers and learned a lot from the various ways people try to solve them https://m.youtube.com/watch?v=4t1K66dMhWk https://m.youtube.com/watch?v=4t1K66dMhWk
- deleted 4y ago[deleted]
- tbillington 4y agoHe also admits he hasn't written more than a hundred lines of code with it before, and that was 4 years ago, more than half rusts lifetime ago. My understanding is his priorities are C level control over memory, fast compiles, and ergonomics for the kinds of operations he commonly does. Rust solves for memory/ergonomics, though the strictness it holds you to is in opposition to what (I understand) he considers ergonomic access & control of memory. Therefore rust solves ~1 of his priorities, so it's not really a good fit. To extrapolate that to "doesn't solve the hard problems" is another logic step that I probably don't agree with.
- mrlonglong 4y agoAnd I was thinking this was referring to the unreal mode on the 32 bit x86 processors which would have been very cool if it was possible with Rust.
- deleted 4y ago[deleted]
- Ygg2 4y agoIt might be. I think Rust can run on 16 bit processors. In theory.
- malkia 4y agosame here - firs reaction in my head was this, and then I knew (milliseconds) later it'll be about the Unreal Engine... but "Unreal Mode" is stuck there first deep into the L0 cache line.
- mrlonglong 4y agoModern processors have such massive caches that you could run MS-DOS entirely within a cache.
- PixelOfDeath 4y agoGet real, we can no longer protect you from the fact that unreal engine only runs in long mode!
- rtpg 4y agoUnreal really is a fun tool to use, and I highly recommend it over Unity for stuff like blueprints. Things like this are awesome as well. What I really really want (and maybe I can have this easily!) is to be able to inline some C++/Rust inside a blueprint. Sometimes there are expressions that would be way easier to type out, or some tricky state logic that I can express with prose more nicely than with arrows. I imagine the "serious" thing to do is to build out the C++ in some other file and then do the thing with my blueprint, but imagine if we had a completely smooth gradient for upping the tooling from blueprint to C++ when needed!
- coolspot 4y agoAFAIK you can call C++ code from a blueprint and other way around.
- ferrumfist 4y agoYou can using these function macros to C++: UFUNCTION(BlueprintCallable) // This is a purely C++ function that is exposed to Blueprints and can be called from blueprints UFUNCTION(BlueprintNativeEvent) // This can be implemented in C++, Blueprint, or both (in the Blueprint implementation, call the Parent method and it will run the C++ function and then run the Blueprint function) UFUNCTION(BlueprintImplementableEvent) // This is a purely Blueprint function (though it is defined in the C++ header) that can be called from C++. I believe there may also be some funky reflection code you can create to invoke Blueprint functions from C++, but there's very little reason for that as BlueprintImplementableEvent does that in a cleaner way. Source: https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/GameplayArchitecture/Functions/ https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScrip...
- rtpg 4y agoYeah I’m talking more about the UX of doing it. I mean really I would love some ML-like language I could write some code snippets directly into the blueprint. Like anonymous functions but for blocks. Would be a disaster in a professional context but I would like it lol
- sk0g 4y ago
- sanxiyn 4y agoThis reminds me of Unreal.js, which allows you to write games with Unreal Engine in JavaScript (V8, to be specific): https://github.com/ncsoft/Unreal.js https://github.com/ncsoft/Unreal.js.
- techdragon 4y agoSurprised to see nothing about the C++ interop work using cxx (and friends). I looked into using this approach when I was playing around with the idea. Writing lots and lots of C wrappers seemed … wasteful.
- eggy 4y agoI'm waiting on Verse a new scripting language for UE by Epic called Verse. A Twitter thread posited it may be called Unreal Verse ;) It is supposedly inspired by Smalltalk and has some Lispy goodness. Can't wait. I played with Rust, and I think it is fine, but too much overhead for me to get productive with it. But that's just me. I click more with Lisp and terse languages (J, APL, Scheme, etc.). So many options to be grateful for!
- capableweb 4y ago> has some Lispy goodness Some "lispy goodness" like what? Is it s-expressions? Or do you mean like it has things lisp invented: things like conditionals ("if/else" statements), garbage collection, recursion and first-class functions? If the first, that'd be super interesting! If it's the latter, tons of programming language have implemented features like that before :)
- wudangmonk 4y agoSince most of those features are common now then I would guess its the ones that are not common. From smalltalk I would like the message system so that all messages to an object only have one entry point. From lisp I would like the macro system and that it all looks like the same language and not the regexp-frankeinstein thing that Rust has.
- eggy 4y agoI hope they don't go down the Rust path. A scripting language or DSL needs to be simple for game dev. They certainly are not going to rewrite UE5 from C++ to Rust!
- eggy 4y agoIt is so new, I couldn't tell you other than I had read it was going to be a mix of Smalltalk with some Lisp features. I think a talk of a REPL with hot reload while your game is running type of thing, and Simon Peyton Jones of Haskell fame is now a fellow at EPIC working on Verse among other things. Maybe it will be more Haskell-ish? Excited in any case to use something other than C++ and a hot reload REPL sounds great!
- the__alchemist 4y agoWhat use cases would be this suitable for? It seems this approach is a bit of a hack that would fall apart in use. It would be nice to program games using Unreal, using the Rust language, but this doesn't sound like that. I respect that making FFI bindings to Rust would be very difficult or impractical, but that's what I think would be interesting.
- zinlencer 4y agoI am always skeptical about these type of projects. Out of the box Unreal Engine supports C++ and Blueprint. The problem with C++ is the slow compile times, and if you make mistakes the engine crashes. In general you produce stuff slower by using C++. Blueprint is a visual scripting tool, it compiles fast. But it stores code as a binary blob in source control. And I'm personally not a fan of visual scripting, I would prefer scripting by just writing code. So generally I prototype in Blueprint and then rewrite in C++ later on. I would love an intermediate language that has fast compile times and saves as a source file instead of a binary blob. The problem is most of the projects that integrate with another language get abandoned after a while. MonoUE was abandoned, USharp was abandoned, now the newest attempt to integrate UE with C# UnrealCLR looks abandoned. SkookumScript doesn't support UE5. Haxe support for UE was abandoned. Do I really want to risk writing a ton of code in a language that might not support future engine versions? To be honest, I don't want to take that risk.
- michaelsalim 4y agoThis is really cool. It's projects like these that makes me want to experiment with random things. It might not make sense or feasible but that is what's fun about it :)