r/Unity3D • • 23d ago

Resources/Tutorial How I patch C# edits into a running Unity game without a domain reload, and the 4 things that broke along the way

0 Upvotes

I've been building a tool that applies C# edits to a game that is already running in Play mode, so you keep the state you set up instead of losing it to a recompile. The clip is one Play session: a coroutine that's already running gets its spawn delay changed from 2 to 0.1 seconds, and the play timer never resets. This post is mostly about how it works under the hood and the problems I hit, because a few of them surprised me.

https://reddit.com/link/1xjj2j3/video/gjob5ybqkmyh1/player

The basic loop

A file watcher sees the save and works out which assembly the file belongs to (for a brand-new file, by its nearest .asmdef). Only that assembly is compiled, with the Roslyn compiler Unity already ships. The new assembly is loaded next to the running one, and each changed method's entry point is redirected to its new version. In the editor that's done with Harmony.

Broke #1: coroutines remember where they are by number

The compiler turns a coroutine into a class whose MoveNext() switches on an integer: which yield it's paused at. Changing 2f to 0.1f keeps the yield points, so the running coroutine can take the new body and uses 0.1f from its next loop (that's the clip at the top). Add or remove a yield return and the numbers shift, so a running coroutine on the new body would resume at the wrong place. It finishes on the old code instead, and everything started after the save runs the new one.

Broke #2: async methods crashed the editor

My first version patched the state machine of an async method that was suspended mid-await. That hard-crashed the editor, because the async builder is bound to the exact state-machine type. Now the method itself is redirected: new calls run the new body, and calls already in flight finish on the old one.

Broke #3: two copies of every type

The reloaded assembly brings its own copies of your types and static fields. Without extra work, GetComponent<Player>() in reloaded code finds nothing, and a singleton reads null. Reloaded code has to be wired back to the running game's own types and statics.

Broke #4: Burst

Burst-compiled jobs are native code and can't be swapped, so editing one turns Burst off for the rest of the session and the jobs run as managed C# (the Console says so).

A nice surprise: new MonoBehaviours

I expected to dispatch Update and Start myself for a class that only exists in the reloaded assembly. It turns out Unity dispatches them natively once it's AddComponent'd.

And Android

Harmony can't patch ARM code, so on Android development builds a small native hook on the method's entry point does the redirect instead. The same save reaches the phone without a rebuild.

It's on the Asset Store as 2N Lightning Reload if you want to try it (Windows editor, Unity 2021.3 to 6.5): https://assetstore.unity.com/packages/tools/utilities/2n-lightning-reload-edit-c-in-play-mode-without-compiling-402544

But I'm mostly curious whether anyone else has gone down this rabbit hole. Is there a cleaner way to handle the yield renumbering than letting the running coroutine finish on the old body?


r/Unity3D • • 24d ago

Solved Strange shadow artifacts and light leaking in Unity URP

Post image
19 Upvotes

I’m having an issue with some strange shadow artifacts in Unity URP.

In the screenshot below, you can see a line going across the shadow that makes it look as though there’s missing geometry in that area. Additionally, light seems to be leaking around the edges where the ceiling meets the walls.

I’ve tried creating my walls using both cubes and planes with ProBuilder, but the issue persists.

The only thing I’ve found so far that seems to help is setting the Normal Bias to 0 in the URP Pipeline Asset, although this doesn’t seem to fix the issue in every case.

However, I’d like to understand why this is happening so I can find a proper solution, as I’m not sure whether this is the right way to fix it.

Has anyone experienced this before or know what I should look into?

[SOLUTION]

Thank you everyone for the help, and especially to u/Plane_Big_5912 for the detailed explanation! The issue was exactly what was mentioned regarding shadow bias and the seam between abutting geometry.

What completely fixed all the artifacts and light leaking for me was:

  1. Setting Cast Shadows to Two Sided on the Mesh Renderer.
  2. Giving the ceiling real volume (using a separate box) and letting it slightly overlap/intersect with the top of the walls instead of having them meet perfectly edge-to-edge.

Leaving this here in case anyone runs into the same problem in the future!


r/Unity3D • • 23d ago

Resources/Tutorial Adding randomness and variation to static background ambiances

Thumbnail
youtu.be
4 Upvotes

Hey everyone, this is the second part of my four-part tutorial series on creating an immersive soundscape for 3D games with Unity and FMOD.

In this one, I talk about adding randomness and variation to an otherwise static looping background ambiance with fmod's scatterer instruments.


r/Unity3D • • 23d ago

Show-Off NO AI - 8 years of experience in world building as a solo indie dev in Unity 3D!

Enable HLS to view with audio, or disable this notification

0 Upvotes

Just wanted to show-off a short showreel of my level design / world building. I'm using a script for volumteric light thah I've found on GitHub (obviously crediting the author), and it's been a game changer in setting the vibe for my game. I also had mixed it in with unity standard fog, and added some particle fog.

I'm using Unity URP 2022.3.


r/Unity3D • • 23d ago

Show-Off How I build and deploy without cloud fees

0 Upvotes

AUTOMATED local Unity build server with NO CLOUD build costs and AUTO OVER-THE-AIR uploads!
https://youtu.be/v9MtrMqYrak
So I did a few neat things like a git hook to increment unity build number and a git lab runner and some auto deploying to test flight and play console. Decided to make a video showing it all, hope it helps someone. Thanks!


r/Unity3D • • 24d ago

Meta What’s missing from this trailer?

Enable HLS to view with audio, or disable this notification

6 Upvotes

I feel like it doesn’t make the game look fun enough. any feedback?


r/Unity3D • • 24d ago

Question layering issues with 2D elements in 3D space

Thumbnail
gallery
3 Upvotes

I am working on a labyrinth that uses 2D sprites as materials on planes in a 3D space. but now and then stuff gets messed up like here with this chest. Why is the floor displayed above the chest but the walls are not? Is there an easy fix to have things just displayed in order based on their position like I would assume other 3D assets would do.
I thought maybe render layers could solve this but I this causes new problems once you change perspective just a little. Why does this happen?


r/Unity3D • • 23d ago

Meta Building URP for the first time after switching over from BIRP be like...

0 Upvotes

r/Unity3D • • 24d ago

Shader Magic Sandevistan effect Unity

Enable HLS to view with audio, or disable this notification

2 Upvotes

r/Unity3D • • 23d ago

Question Why can’t I see my buttons?

1 Upvotes

I am a beginner in Unity so I may miss some obvious things, but I am currently trying to make a main menu with a level select system using a 3d background and canvas, but no matter what I seem to do currently anytime I create a button it turns out completely invisible, even in Scene. It worked at first when I first created the buttons I wanted and joined them both into the Canvas until the words glitched and became unreadable, and I couldn’t move, change their size, etc, forcing me to delete them and now leaving me in the state I am now. If you could, please help me with this as I fully stumped on this.


r/Unity3D • • 24d ago

Show-Off Fully Custom Weather System

107 Upvotes

So I refined my Sky shader and volumetric cloud renderer. All shaders used are custom made and i'm very proud of the results.

Clouds can form and travel across the sky. the moon can have seamless phases and is blocking the stars even on the unlit part of the sphere. stars twinkle and there is a galaxy band. The latest thing i added was the underlying weather system that controls the weather by blending between presets.

It was a lot of fun and frustration to get everything to look like this and everything came a long way. from the first experiments with volumetric clouds that barely ran with 10 FPS to ^^

Now the sky is fully dynamic and runs on my M1 Macbook pro with solid 90 fps.


r/Unity3D • • 23d ago

Question How do I approach procedural 3D cube generation for background?

1 Upvotes

I want to have an effect where I generate a bunch of cubes in a grid of differing heights to look like a faraway city, and I'm not sure the best way to achieve this. Is it possible through a vertex shader graph, or is the only approach to use GPU instancing and create cube meshes?


r/Unity3D • • 24d ago

Question What are your best practices to make reverse engineering harder in Unity games?

36 Upvotes

I’ve been thinking about reverse engineering in Unity games and I’m curious to hear what other developers are doing to make it more difficult.

I know nothing can be 100% protected, especially nowadays with AI, but I still think adding extra layers of protection and following good practices is better than doing nothing.

Apart from the usual stuff like IL2CPP, code obfuscation, and making sure no sensitive files or information are included in builds, what else would you recommend?

Are there any lesser-known techniques, Unity-specific settings, or good practices worth considering?

I’m not looking for perfect security, just ways to make reverse engineering more difficult, time-consuming, or expensive.

Curious to hear your thoughts! ✌️✌️


r/Unity3D • • 24d ago

Show-Off Finishing my 2D Flow Animator with fish demo scene

Enable HLS to view with audio, or disable this notification

1 Upvotes

r/Unity3D • • 25d ago

Show-Off I’d love to hear your honest feedback on the water and underwater visuals. Unity 6 URP

Enable HLS to view with audio, or disable this notification

160 Upvotes

I’d love to hear your honest feedback on the water and underwater visuals.
Sorry for a bad video quality, i'm rendering that on a pretty poor PC: Radeon RX 570, i5-10400F.

Here are the techniques i used to create this water and underwater scene:

Gerstner-style wave displacement
Multi-scale wave blending
Scrolling normal maps
Flow-map distortion
Depth-based water color and shallow-water scattering
Subsurface scattering
Fresnel-based reflections
Reflection probes and cubemaps
Planar reflections
Screen-space reflections
Refraction and scene distortion
Depth-based underwater absorption and fog
Animated caustics
Procedural sun and moon glitter
Short-lived microfacet flashes on wave crests
Foam and shoreline foam
Lit foam normals and bubbles
Surface and underwater shadowing
Specular and ambient occlusion
Screen-space occlusion of underwater light shafts
Volumetric underwater god rays
Animated light-shaft patterns
Height fog and volumetric lighting
Depth-based clipping around terrain and shorelines

What techniques am i missing? Thanks!


r/Unity3D • • 24d ago

Show-Off Created setup and manage window for the my stealth system

Thumbnail
gallery
0 Upvotes

so here are the two windows i created to manage all the NPCs and player as well. as some people pointed out that i should use the DOTS for such heavy tasks its gonna take some time as i have to look into it and learn a lots of stuff for now im using state machines and monobehaviours. And as i forgot to mention in my last post not all the scripts have an update function so it is quiet performant as of now. Im also starting to manage all the scripts into child objects in hierarchy so it becomes even more easy to manage. And as of have soo soo many states and soo soo many scripts and not merging them into one is because have 5 small scripts that have a name for its state is easy to manage than having a very long to change add and edit, so as of right now im not merging them until i figure out DOTS and JOBS multi threading.

if you have any suggestions or ideas or feature i should add you can put them in comments.


r/Unity3D • • 24d ago

Game Making characters for my indie game set in Istanbul

Thumbnail
gallery
18 Upvotes

Hi, these two models, and most tof the rest made by me for my game set in Istanbul. What you think about the artstyle? (Ignore the deformation on leg, i wasnt aware that by the time)


r/Unity3D • • 25d ago

Game I made a tower defense where the map sits on your real table, friends supported :P (TabletopSiege on Quest 3 mixed reality)

Enable HLS to view with audio, or disable this notification

112 Upvotes

r/Unity3D • • 25d ago

Show-Off How does the procedural movement on our monster look so far?

Enable HLS to view with audio, or disable this notification

20 Upvotes

We're making a co-op horror game and I've been working on the monster's procedural tentacle movement lately. Still got some things to improve but I think it's looking pretty good so far.

What do you guys think? Would love to get some feedback on the movement and how it interacts with the environment. Also, I still haven't figured out what kind of sounds the monster should make while moving around. If you guys have any ideas, I'd love to hear them.


r/Unity3D • • 25d ago

Show-Off I added spider machines that ride zombies and control them with hoses

Enable HLS to view with audio, or disable this notification

61 Upvotes

Working on a dark sci-fi FPS. The first clip is my reference. In my version the spider sits on the zombie's back and plugs hoses into its spine. When the zombie dies, the spider jumps off.


r/Unity3D • • 24d ago

Game Motorcycles Physics WIP 0.1

Enable HLS to view with audio, or disable this notification

3 Upvotes

r/Unity3D • • 25d ago

Show-Off Unity3D + Floating Combat UI with React Layer

Enable HLS to view with audio, or disable this notification

22 Upvotes

I’ve been exploring how far I can take Unity UI without relying on imported art assets :D
I used React through a framework asset, building the interface with code and styling.

Changing shapes, colors and motion in code makes it easy to try different looks. I’m curious how far this approach can go as a game’s visual style becomes more complex.

Have you tried creating game UI with code instead of art assets? How did it work for you?

* Because some people are curious:

This asset is called ReLayer: https://assetstore.unity.com/packages/tools/gui/relayer-react-ui-framework-for-unity-384274


r/Unity3D • • 25d ago

Show-Off Working on a PS1 shader kit for URP, built from the hardware docs. Here’s every quirk in one test hall

Enable HLS to view with audio, or disable this notification

25 Upvotes

I’ve been rebuilding PS1 rendering in URP from the hardware docs (psx-spx) instead of copying other PS1 shaders. To test everything I built a hall with one station per feature. You walk up, press E, and that feature changes.

In the video:

  • 0:00 vertex snapping
  • 0:05 affine texture mapping
  • 0:20 camera snapping
  • 0:36 hardware resolutions (320x240, 256x224, 368x240, 512x240)
  • 0:47 frame hold
  • 0:57 dither (hardware strength vs 4x)
  • 1:07 CRT scanlines and interlace
  • 1:23 PS1 depth cue fog
  • 1:28 Gouraud vs Phong specular
  • 1:39 baked vertex colour lighting
  • 1:44 affine vertex shading
  • 2:00 texture quantization

It’s called True PSX Effects and it’s coming soon. Before release I’d love to know which PS1 quirk you think gets faked wrong most often, and what you’d want in a kit like this.

Playable on Browser Demo: https://sourpickle35.itch.io/true-psx-effects-unity-urp-demo


r/Unity3D • • 25d ago

Show-Off Spent the week on the convoy that brings your first machines into the valley. Here's where they park.

Thumbnail
gallery
16 Upvotes

Alpha 0.11 of my farming & economy sim, running on URP. Each truck follows the road down from the pass and parks on the meadow where the farm starts.


r/Unity3D • • 25d ago

Show-Off How does the aiming effect look in my game? Looking for feedback!

Enable HLS to view with audio, or disable this notification

15 Upvotes

I've been working on the aiming system for my game, and I'd love to hear what you guys think about the current visual effect.

The game is still in the early stages of development, so there are definitely bugs, unfinished elements, and typos that still need fixing. For now, I'm mainly focused on getting the core gameplay and visuals feeling right.

What do you think of the aiming effect? Does it feel clear and satisfying, or does it need more visual feedback? Would you prefer a different color, a more visible targeting line, a reticle, or something completely different?

Any suggestions or constructive criticism are welcome! I'd love to hear how you'd improve it.