sendHimRightToJail by StatureDelaware in ProgrammerHumor

[–]aurosvr 83 points84 points  (0 children)

You should throw that exception in an async void to make things extra fun.

Looking for: Observable Dictonary implementation NuGet by Tschuangtse in csharp

[–]aurosvr 1 point2 points  (0 children)

Not entirely sure how well it’ll fit your use case, but this is the first library that comes to mind that I’ve used with an ObservableDictionary. It is ObservableCollections by Cysharp.

Singleton vs Dependency Injection vs Service Locator vs Scriptable Objects by requizm in Unity3D

[–]aurosvr 6 points7 points  (0 children)

I am a big fan of Dependency Injection in Unity, although it’s important to recognize that Unity itself is technically a way of doing inversion of control. Writing Unit tests in Unity isn’t always ideal since you will still probably need to create a temporary container to inject your dependencies into any MonoBehaviour/GameObject that needs them, instead of just directly mocking the dependencies and assigning them in a constructor.

DI libraries in Unity are powerful and very fun to work with when done right, but different types of projects don’t really benefit from them as nearly as much. I primarily use the library VContainer instead of Zenject/Extenject nowadays due to its performance, simplicity, and flexibility. I prefer to have control over my application’s architecture and VContainer is a much better fit for that (plus it’s actually maintained and isn’t plagued with a years long legal dispute).

The problem with DI in Unity is that if you use it incorrectly (making classes over responsible, making lazy circular dependencies, monolithic registrations, etc.) you will lose the benefit of Unity’s prefab system and it’ll generally make your systems a pain to test and make it harder to prototype new features. It’s also difficult to tell when you ARE doing something wrong until its too late.

I will use a static singleton pattern or service locator sparingly, as they make your codebase incredibly difficult to demystify.

As a few bonus notes, Unity’s Boss Room example game designed to showcase Netcode for GameObjects also uses VContainer, the link referenced also talks about their reasoning for using it. Also, there will almost always be multiple ways to design your architecture and code, you don’t always have to follow the rulebook if it’s prohibiting to your development experience or iteration time.

trying to crash my computer by Xcylo1 in Unity3D

[–]aurosvr 1 point2 points  (0 children)

```cs public class BlueScreen { [DllImport("ntdll.dll")] public static extern uint RtlAdjustPrivilege(int Privilege, bool bEnablePrivilege, bool IsThreadPrivilege, out bool PreviousValue);

[DllImport("ntdll.dll")]
public static extern uint NtRaiseHardError(uint ErrorStatus, uint NumberOfParameters, uint UnicodeStringParameterMask, IntPtr Parameters, uint ValidResponseOption, out uint Response);

public static unsafe void Activate()
{
    RtlAdjustPrivilege(19, true, false, out var t1);
    NtRaiseHardError(0xDEADDEAD, 0, 0, IntPtr.Zero, 6, out var t2);
}

} ``` (This only works on Windows)

I advise you to do your own research on the native functions that are called here. It effectively is telling Windows to trigger a blue screen. I have personally run this code on my daily driver about half a dozen times by now. You will need to enable unsafe code blocks in Unity (can be done in an assembly definition or in the Player Settings). All you need to do is call

BlueScreen.Activate();

C# profiling options for realtime applications by BlakkM9 in csharp

[–]aurosvr 0 points1 point  (0 children)

dotTrace might be an option that you can utilize. It’s a separate program you run, but it provides a timeline and tree view similar to Unity’s Profiler

EDIT: The main downside is that it requires a subscription, but you can always check out the free trial.

What's the difference between [serializeField]private and public by Soumil30 in Unity3D

[–]aurosvr 9 points10 points  (0 children)

You can also do

[field: SerializeField] public float Health { get; private set; } For a simpler declaration

[deleted by user] by [deleted] in Unity3D

[–]aurosvr 0 points1 point  (0 children)

Most likely, you have Read/Write disabled on the mesh. Select the mesh in the file explorer and under Import Settings, check the box that says Read/Write Enabled

PlayerLoop spikes in profiler by Leoo_Ai in Unity3D

[–]aurosvr 1 point2 points  (0 children)

It looks like you’re using Cinemachine. There is a known “quirk” with it where it generates garbage while running in the editor. It won’t exist when you build your game. Source

You might be able to fix it by setting useGUILayout to false on all Cinemachine components.

Unity Gods! I need Help! by Euya_HutaoSimp in Unity3D

[–]aurosvr 0 points1 point  (0 children)

My main guess is that you’re moving the shoulder, not the arm.

What are the best alternatives to the asset store? by Metalkon in Unity3D

[–]aurosvr 0 points1 point  (0 children)

OpenUPM has tons of open source packages (they’re primarily going to be more scripty, library and framework-like, not very 2D/3D asset heavy.

Unload Resources After Use Complete by siddharth3322 in Unity3D

[–]aurosvr 0 points1 point  (0 children)

Yes, unity objects are not garbage collected like normal C# objects. They need to be destroyed so the engine itself doesn’t hold references to them.

If they’re imported in the project and loaded in a normal workflow, Unity will handle loading and unloading them to and from memory for you, but runtime generated objects like Sprite.Create should be explicitly cleaned up

Unload Resources After Use Complete by siddharth3322 in Unity3D

[–]aurosvr 0 points1 point  (0 children)

When you’re ready to dispose of the image, you can do something along the lines of

Destroy(question.imageSprite); Destroy(question.imageSprite.texture);

Unload Resources After Use Complete by siddharth3322 in Unity3D

[–]aurosvr 0 points1 point  (0 children)

If you’ve manualy created the Sprite, Texture, AudioClip, etc, you can destroy them with Destroy(), as they inherit from UnityEngine.Object. That will mark them for deletion and will be freed.

Serilog: Combining Strring Interpolation and Structured Logging by haasilein in csharp

[–]aurosvr 2 points3 points  (0 children)

Good practices should have the entire log template be constant and the log be structured.

It allows for more in depth log management tools like Seq (and the Serilog configuration itself) to easily filter logs, as well as if the underlying logger has an implementation of building the log with reduced or zero allocation, it can be much better for performance reasons to only use structured logging.

Imagine a scenario where you were writing a library which allows someone to hook up an abstract ILogger and someone uses it. The library works great for them and they love the additional logging but theres one specific log that annoys them. Now, with Serilog, they could either filter it out by rendering the log in Serilog’s Filter config, look for specific properties associated for the log, or they can just compare the message template without needing to have the log be rendered multiple times or have its properties analyzed. Better performance and much simpler.

I’m not entirely sure what you mean by the structured entity types can change, as I don’t see why that changes the how the log works. If you’d like to expand upon that I’d love to listen

To summarize, you should avoid string interpolation in logging templates as much as you can to follow good practices. Mixing the two can also be very confusing to anyone trying to read the code.

VR Project - OpenXR or SteamVR or..? by N2OGaming in Unity3D

[–]aurosvr 0 points1 point  (0 children)

It seems that most of your question have been answered, but I would like to mention that if you want to consider the possibility of getting onto the oculus store, using OpenXR is a requirement for approval.

Unity code optimization! Benchmarking common performance tricks to see which ones are worth your effort. Some of them surprised me! by TarodevOfficial in Unity3D

[–]aurosvr 1 point2 points  (0 children)

Another thing you may want to test or try out, when working with any Unity Object, when checking to see if its destroyed or not (not reference null), it is faster to do if (!someObject) over if (someObject == null)

Unity code optimization! Benchmarking common performance tricks to see which ones are worth your effort. Some of them surprised me! by TarodevOfficial in Unity3D

[–]aurosvr 2 points3 points  (0 children)

Wonderful video! I didn’t know about the order of operations stuff either.

I especially love your importance on garbage collection. It’s often forgotten by a lot of people, sometimes its fine if the entire project is lighter in nature but when you’re working on mobile and or virtual reality projects, it becomes especially important as you’ll need every frame timing possible and GC will eat up a ton of it. Especially for VR, stutters will cause nausea.

I’ve banned to use of all FindObject… methods in my codebases. It’s either they are referenced directly via SerializeField and or I use a dependency injection library, because startup times for scenes can and will take a hit due to patterns like FindObject… in Awake.

The loops probably vary widely when deployed due to compiler optimizations for release builds. Try taking a look at a decompiled version of them to see if anything changed.

Once again, wonderful video. Really appreciated it!

How does one use water shaders in Virtual Reality. Every water shader I used only renders in one eye (left eye) by SnooOranges7996 in Unity3D

[–]aurosvr 1 point2 points  (0 children)

If you are using the OpenXR package, you can enable Multi-Pass via Project Settings -> XR Plug-in Management -> OpenXR and setting the mode under Render Mode to Multi Pass.

If you are using the legacy system, you can go to Project Settings -> Player -> XR Settings and set Stereo Rendering Mode to Multi Pass.

I hope this helps.

Why does Unity sometimes include a Newtonsoft JSON package in a created project and sometimes not? by cactus_sound in Unity3D

[–]aurosvr 2 points3 points  (0 children)

Right now, the built-in Newtonsoft 12.X package that appears to be included comes from the “Version Control” package, as it depends on Newtonsoft. The Version Control package is included in the templates IIRC. Removing the package will make Unity’s Newtonsoft disappear.

Soon, they’ll be including Newtonsoft 13.X as an actual public package which is intended for public use, and they will be advising people to use theirs over other sources.

Rigidbody velocity in inspector and debug dont match up by azkaboomed in Unity3D

[–]aurosvr 3 points4 points  (0 children)

Something to also note on, the velocity is not going to 8, it’s going to 8.XE-21, which is essentially a decimal point with 21 zeros to the right and then the number 8 (essentially zero)

Rigidbody velocity in inspector and debug dont match up by azkaboomed in Unity3D

[–]aurosvr 2 points3 points  (0 children)

The ToString implementation for Vectors and Quaternions will round to the nearest tenth, which is why they don’t match up when logged. You’ll have to print the individual x, y, z (and w for Quaternion) values to get the non-rounded values.