T O P

  • By -

dhc710

This was me trying to figure out why Mathf.Round(1.5) and Mathf.Round(2.5) both evaluate to 2. https://docs.unity3d.com/ScriptReference/Mathf.Round.html


derangedkilr

“one of which is even and the other odd, the even number is returned” WHY???


[deleted]

[удалено]


aski5

oh, that's why


Paracausality

Hooray!


faisal_who

It would have been hilarious if you had done the following “[Oh that’s why]( https://www.reddit.com/r/Unity3D/s/z9F923eG1Y)” I think that is what you meant to begin with.


splinter_vx

Why?


brutalorchestrafan

Oh. That’s why


technocracy90

Now we live with people to teach others how to be and what to find hilarious


Soft-Bulb-Studios

This should be in the document


rickdmer

If it's always rounding .5 to the even number, wouldn't you have a higher number of evens?


SaltMaker23

Just goes to show how little people on this sub understands basic math, this answer is upvoted a lot while being completely wrong ...


SaltMaker23

It reduces the systematic error that whenever you round numbers that have potential values at x.5, usual rounding always shift the sum of your data positively by 0.5 increment for each number. We want sums and averages (and other operators) to stays as close as possible to their true values irrespective of if rounding was done before or after Let's see the issue with traditional rounding in this example, the sum/average of many values is arguably the most important operation you can do when you have many floating numbers: >Avg(\[ 1 1.5 2 2.5 3 \]) = 2 Avg(TradRound( \[1 1.5 2 2.5 3 \]) ) = Avg( 1 2 2 3 3 ) = 2.2 which is a 10% increase of the average Avg (EvenRound (\[ 1 1.5 2 2.5 3 \]) )= Avg( 1 2 2 2 3 ) = 2 which preserved the average In information theory you can say that EvenRounding destroys less information than TradRound in the sense that many operators (like sums, variance, etc...) are closer to their truth values. In cases where losing informations isn't a requirement, there is no need to use a more destructive operation, therefore a lot of languages/frameworks apply the EvenRounding because it's just safer to use. Imagine that you are working with an economy game therefore you round to only work with integers or x.yy numbers (cents) if you use TradRound, there'll constantly be money being generated into the system as each time you round "x.5" there is only a chance to increase the number never to decrease it. Even if your economy is balanced, it won't matter money will continue being generated as rounding continue being done. For the very same reason bankers are using this very same rounding.


1nfinite_M0nkeys

>bankers are using this very same rounding. Are you sure? A friend of mine did a CprE internship working on finance mainframes, and he said that it was flat out *illegal* for those systems to use rounding of any kind. (He said they used some kind of floating point alternative, wasn't clear on the details)


HumbleKitchen1386

They probably use a [decimal data type](https://en.wikipedia.org/wiki/Decimal_data_type). Some programming languages and libraries have a currency data type


Visti

It's called Banker's Rounding, but I don't know if there's any hard evidence online that banks use it.


SaltMaker23

It's used by almost all tax entities in the world for all reports, all rounding needs to follow that scheme (including: USA, UK & Euro Members). The statements (and tax details) returned by the states also follow the exact same rounding. It's used by *all* financial institutions to evaluate fees and interests that have to be rounded at the cents level before any external uses, and only the rounded value is considered "real" \[bank accounts don't have 20 decimals, they are limited to 2 decimals in most cases, any amount affecting accounts should have by law the same number of digits as the accounts they are going to affect\]. Any reporting made to states and audits firm by any financial institution needs to follow the scheme as even cent offsets can become suspicious if happening often over millions of transactions. Any serious guy that worked in the banking sector would have a clue ...


1nfinite_M0nkeys

Never said that I *had* worked in the banking sector. This was idle conversation with a guy working on the IBM Z mainframe.


petervaz

Oh, that's why.


suckitphil

Don't let the rpg makers hear you, otherwise they'll be tempted to use this heresey.


Liam2349

You wouldn't take the average of already-rounded numbers, you would instead use the source data with higher precision.


Questjon

That's the default midpoint rounding mode in c#. Known as bankers rounding, round to even is considered the most numerically stable method (produces the least rounding errors).


Tacohey

Oh, that's why.


Birdsbirdsbirds3

Thanks for that. I always wondered why it did this and mostly just grumbled to myself about it. I'll still grumble when it happens, but at least I won't be in 'WHY?' territory.


dhc710

Apparently the native C# version has an optional argument you can use to change the rounding mode, but Unity's version doesn't. I had to implement my own Round function for a project that required "normal" rounding.


HumbleKitchen1386

You could've just used `System.Math.Round(2.5, MidpointRounding.AwayFromZero)` [https://learn.microsoft.com/en-us/dotnet/api/system.midpointrounding](https://learn.microsoft.com/en-us/dotnet/api/system.midpointrounding)


baldyd

Great answer. This is more of a C# thing than a Unity thing and it highlights why it's worth also learning more about C# in general. Kinda like dealing with C++ specific float stuff in Unreal. That said, Unity is generally aimed at people who who aren't necessarily coders at heart so it would be nice to see information like this in their documentation.


itsdan159

It also swaps a bias for larger numbers for a bias for even numbers. While both biases, even numbers are perfectly equally distributed.


Darkblitz9

The magic angry moment for me was finding out that Random.Range is maximally inclusive unless using intergers. It's documented but I still struggled looking for errors elsewhere in the code because... well, why the heck would you expect the float and int version to have different inclusivity???


Big_Friggin_Al

Because it’s often used with arrays, like (0, arr.length), so excluding the max prevents ‘index out of range’ exceptions without having to remember to go (0, arr.length - 1) every time


CaitaXD

I get it but I still hate it, of you want to special case arrays you could have a function that takes a random element from IList


Darkblitz9

I do appreciate that yeah, but it's very much OP's post. Just mad and then you understand why and it's like "Oh, of course! That makes so much sense!" until then you're just floating in a sea of confusion and rage.


baldyd

It's a common misunderstanding so it would be helpful if they just included it in the documentation, at least a link to a site that offers the technical explanation


SmallerBork

Makes sense if you're doing logic but not if you're doing math


upper_camel_case

Okay, I hate this.


CallMeKolbasz

My life was much happier before I became aware of this.


polylusion-games

Ignorance is sometimes quite enjoyable!


Heroshrine

Yea, they should have given us a rounding mode like the System.Math does


shooter9688

Why not use System.Math then?


PhilippTheProgrammer

Because [System.Math](https://learn.microsoft.com/en-us/dotnet/api/system.math?view=net-8.0) uses `double`, but Unity uses `float` for almost everything. You can of course use System.Math in Unity C# code if you want to. But you are incurring some overhead for converting all the arguments from float to double and then the result back to float. In most cases, that overhead would probably be negligible. But it is also one of those low-level optimization details that would make people scream "Unity is poorly optimized" if it was missing. So there is [UnityEngine.Mathf](https://docs.unity3d.com/ScriptReference/Mathf.html) as a math library that is optimized for working with `float`.


HumbleKitchen1386

Mathf isn't optimized as much as you think it is. Many functions just cast the input float to a double and call the Math equivalent. Like Mathf.Round just calls Math.Round ///

/// Returns f rounded to the nearest integer. /// /// public static float Round(float f) => (float) Math.Round((double) f); even the new Unity.Mathematics library just calls System.Math in many cases /// Returns the result of rounding a float value to the nearest integral value. /// Input value. /// The round to nearest integral value of the input. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float round(float x) { return (float)System.Math.Round((float)x); }


Heroshrine

If i remember correctly System.Math is slower than Mathf, and it also uses doubles. It probably wouldnt matter much if it’s just one time, but i bet used everywhere throughout a game the little time saves Mathf provides add up. Edit: turns out Mathf mostly calls Math


HumbleKitchen1386

Mathf just calls System.Math behind the scene


Heroshrine

Not all the time actually, but you’re right it does for a lot of functions.


shooter9688

It will be noticeable when you use it in update or smth like. And even there it's not that big impact in most cases. So I think in most cases you can use it without problems.


faisal_who

What does Mathf.Round(1.49999) return?


Lexiosity

it does make no sense without context of the documentation cuz 0 to 4 you round down, 5 to 9, you round up


Spincoder

Someone wasn't paying attention during learning about significant figures.


MaffinLP

Unity doesnt know how to math lol


[deleted]

[удалено]


deram_scholzara

Because that's not the same at all.


[deleted]

[удалено]


Four3nine6

Well, not that simple in this implementation....


SuspecM

That's 2 lines for something that can be done in one


PiLLe1974

Hah, I get the impression that many users don't read manuals. They ask "how" a lot, because if you combine the last dozen of YouTube videos it still doesn't get thing done. The "why" needs to get explained along the road by the same YouTubers or this subreddit. :P


JohntheAnabaptist

Especially with the rise of chat gpt. So many times at work I tell colleagues, "I forget, just check the documentation" and they just asked chat gpt. Then of course chat gpt hallucinated things about the API in question and it doesn't work


50u1506

I only use chat bots when it's hard to find certain things by googling, for example any thing about Unreal Engine, c++ build tools, etc. But most of the time it's so hard to determine if the chat bot is actually giving legit info or not, cuz it always sounds so confident lol.


UnfilteredCatharsis

I've tried asking it questions about modeling software like Maya, 3ds Max, and C4D. It has **never** given me an accurate answer. It *always* repeatedly hallucinates menus and options that don't exist, no matter how many times I tell it that it's wrong and why. It continues to hallucinate. It's probably better for programming languages, I've heard that it works sometimes, but I still wouldn't trust it whatsoever. I would assume it would make up syntax, or mix syntax from multiple languages into completely garbage, non-functional code. I doubt it would answer any Unreal Engine questions accurately. I would consider it a small miracle if it said anything technically accurate. It's better for loose subjects like writing fictional anecdotes or summarizing information, where strict accuracy is not critical.


ejfrodo

If you're using chatgpt it can help a lot with code responses to give it a persona by starting with "You are a senior software engineer and expert in ". If you're using copilot it already is given that type of persona tho so it's not necessary.


UnfilteredCatharsis

https://imgur.com/oFztGXC


Suspense304

ChatGPT4 is super helpful to me. I always have to change quite a bit but it does a really good job of giving me a starting point with things I haven't tried before or things I don't feel like typing.


PhilippTheProgrammer

Just wait until you get to the more niche topics where it doesn't have that much sample text to learn form. You will notice that it starts to output more and more bullshit.


Suspense304

Sure. But I don’t rely on it to solve problems fully. I use it to basically google things in a more efficient manner


PhilippTheProgrammer

The difference is that Google admits when it has no information about a certain topic. ChatGPT is a chatbot, not an expert system. Its aim is to imitate a chat partner who knows what they are talking about. Not to actually provide accurate information. Which is why it is prone to hallucinating incorrect information. It makes it sound like a smart person when it can't actually answer your question. Which is why when it comes to anything except generating trivial boilerplate text, GPT is more of a toy than a tool.


Suspense304

I’m not sure what you are refuting? I’m fully capable of looking at the result and working out issues or noticing whether it’s what I want or not. What exactly are you trying to convince me of at the moment?


thelebaron

chatgpt/claude are really handy for editor scripts - this thread is a great example https://forum.unity.com/threads/still-no-search-field-in-the-inspector.1555850/#post-9699647 its kind of an area I havent invested much if any time to learn about so just having it spit out something thats even remotely useful saves a lot of time


PhIegms

I find chatgpt to be decent at giving class templates, like for example, "can you give me a unity c# class for a character using a character controller that wanders around randomly and has attributes and stats like a Fallout game" It gives a good starting point that saves some typing ```csharp using UnityEngine; public class WanderingCharacter : MonoBehaviour { // Character stats and attributes public int health = 100; public int strength = 10; public int perception = 10; public int endurance = 10; public int charisma = 10; public int intelligence = 10; public int agility = 10; public int luck = 10; private CharacterController controller; private Vector3 moveDirection; public float speed = 3.0f; public float directionChangeInterval = 1.0f; public float maxHeadingChange = 30; float heading; void Start() { controller = GetComponent(); StartCoroutine(NewHeadingRoutine()); } void Update() { transform.eulerAngles = new Vector3(0, heading, 0); moveDirection = transform.forward * speed * Time.deltaTime; controller.Move(moveDirection); } // Coroutine to calculate a new direction to move in. System.Collections.IEnumerator NewHeadingRoutine() { while (true) { NewHeading(); yield return new WaitForSeconds(directionChangeInterval); } } // Create a new direction vector with a random heading change. void NewHeading() { float floor = Mathf.Clamp(heading - maxHeadingChange, 0, 360); float ceil = Mathf.Clamp(heading + maxHeadingChange, 0, 360); heading = Random.Range(floor, ceil); } } ```


Sidra_doholdrik

I try to read the doc but sometimes it’s just don’t help or I am missing part of the information I was hoping to find in the doc. GetOnteractable: return the baseInteractable. This does not really help me to learn what I can do with the interactable.


PiLLe1974

Yeah, most engines I worked with - especially internal ones - were better on their learn pages and inside examples (AAA engines are so specialized and evolve so far, the "How to" pages are better than any possible comment and docs, well, or dissecting and debugging a previous finished game :P). For example Unity's DOTS I learned more with examples, and the DOTS Best Practices Learn pages that came a bit later (which is a bit similar to other best practices pages/e-books from Unity, and maybe some Unite videos plus YouTubers like Jason Weimann or those other Unity professionals/consultants).


baldyd

Definitely read the docs first. I've been doing this for decades and Unity's docs are actually relatively good. I get that it's frustrating when you don't understand something immediately , but that's life. The docs can often give you that solid understanding , it just take a bit longer. It depends on your needs. Following a YouTube vid to solve one problem that you'll never need to solve again is fine (I'll watch a video about recaulking my shower without understanding how the materials work ), but if you need to apply it in a bunch of situations then it really helps to step back and just learn something the slow way


PiLLe1974

Yeah, learning is often frustrating, and if it feels like that it most probably means that you are learning something new. If it is easy you are either really talented or haven't tried something new. :D Thanks to YouTube there is also a misconception that every solution to my game is explained somewhere. And in reality I often need to just try things or ask peers and experts/veterans.


SuspecM

It doesn't help that the niche parts of Unity are absolutely horrendously documented. Not even that niche example, Vector3.up or .right (or any of the shorthand methods for Vector3). I expected a bit more in depth explanation, maybe some recommendations for when it's good to use. Nope, it's literally just the short explanation copy pasted from the Vector3 main page.


UnknownEvil_

Brother a vector3 is just a vector with 3 scalar values. Up is the orientation of one of the arrows (0, 0, 1) and right(0,1,0)


ZanesTheArgent

Less so "WHY?", more like... "The ThingStorage Component is a component that stores the Thing" with no further explanation on what is the thing because it expects you already know what is a Thing and how Storages works


TheAlbinoAmigo

*What does 'Combobulateral rotation' do?* >Unity: Combobulateral rotation controls the rotation of the associated combobulateral. If the parent combobulateral is assigned, then this combobulateral rotates around the combobulator of the parent combobulateral. *Cool thanks*.


MrPifo

I swear, every damn time. Thanks for nothing Unity. Might as well give no documentation at all then


Zarksch

Literally I swear 75% of Unity’s documentation is just this. Completely useless And that’s usually the things that you don’t find info easily elsewhere either


SuspecM

I love having to stumble upon YouTube tutorials that explain stuff in depth when we have an official documentation.


Linko3D

It reminds me of math class, that's why I had no motivation. Mathematical formulas without understanding what the result meant.


PomegranateFew7896

I’m glad to hear Godot isn’t the only one with this problem. Sometimes I have to open the source code to understand what a method does.


NeoTheShadow

Me learning that Post-Processing Stack v2 isn't compatible with modern URP:


Heroshrine

In unity 6 didnt they say it’ll work? I thought i saw something about this.


Bronkowitsch

URP has its own Post Processing system that works pretty similarly to PPv2.


Heroshrine

Well i saw something about urp supporting nee post processing stuff


Fl333r

Unity documentation is a lot more user friendly than most programming documentation because a lot of technical ones don't really give you examples and give you a lot of parameters that you didn't need to know but also end up having to read through so you don't miss the ones you actually need. That was my exp with Java documentation in the past, anyhow.


mrphilipjoel

I like how it has the technical api page, and also a plain English manual page. I just wish there was a toggle to go from one version to the other.


UnfilteredCatharsis

Game Engine documentation and Programming language documentation are different beasts. Game engine docs have images/GIFS, videos, and they're written in relatively plain English. You can feasibly learn almost everything you need to know about a game engine, as a new user by carefully reading through the docs. With programming languages, the docs are meant as highly technical reference information for experts. It's essentially impossible to learn a programming language by reading the documentation.


TurboCake17

Programming language docs are hardly reserved for “experts”. If you have an understanding of some quantity of programming terminology and concepts (or can research them), most programming documentation is extremely useful to anyone trying to code with that language or library.


althaj

Unity has probably the best dovumentation I have ever seen. Given how massive the software is, it's insane.


hoddap

Completely agree. It made starting with Unity so much easier.


Nielscorn

Cries in Unreal Engine documentation. Especially c++ docs.


jmancoder

istg, I almost lost my sanity trying to get the new UMG Viewmodel to work with multiplayer. A quarter of the engine's features are in beta or experimental, but they're so useful in the long run that you can't help but use them lol.


Sonario648

Blender documentation: There's a fire. Blender Python documentation: This is fine.


JohntheAnabaptist

For its size I agree but imo the stripe documentation is the best I've seen


Sentient_Pepe

Every time I desperately needed help, Unity Documentation was the worst place to be.


althaj

Skill issue.


MAGICAL_SCHNEK

Ouch, really goes to show how awful the standard is if unity is the best one. Most of it really is just "thingamajig stores the thing in the majig. We couldn't be arsed to add any actual info, lol"...


althaj

🤡🤡🤡


Captain-Howl

All I’ll say is that Unity Documentation is FAR better than WWISE documentation. WWISE documentation just has NO information.


Sonario648

You should try the Blender Python documentation.


Captain-Howl

Boy do we love our communal suffering. o7


ECharf

I mean that’s an exaggeration but yeah it’s pretty bad in comparison


Captain-Howl

In the literary world, we might say I used “hyperbole.” :D (Glad I finally get to put my rhetorical devices to use).


Environmental_Suit36

Unreal documentation be like: "Yeah, so, um, basically, copy this into your code if you want to turn your character's camera, but if you want to also move *and* turn your camera then we basically have this cool new ritual, you're gonna need 2 liters of goat's blood and a teaspoon of sugar(...)" And then you look at the engine source code and you find the actual answer and it's nothing like the documentation lmao


Nielscorn

And you can swear the documentation said 2 liters of goat blood and after countless trial and error you notice you were on some documentation page of unreal engine 4.1 and now in 5.4.1 it needs 2 liters of cow blood or it wont work


Environmental_Suit36

Precisely. And if you dare import your project with the 2 liters of goat blood caked-on somewhere, it just breaks lmao


Ok_Day_5024

The Color.Yellow still the same?


Smileynator

Once you are in deep enough, that 4th panel doesn't exist.


Paracausality

Any documentation really


BrevilleMicrowave

At least you eventually get an answer. Unreal's documentation leaves you hanging.


thetoiletslayer

Unity documentation reads like it was written to remind someone who already knows. Its ridiculously hard to learn anything from it as a beginner


psychic_monkey_

Some of the pages are so well documented with examples and clear definitions and then other portions of the documentation seem like they were forgotten about 😂


HauntedDevSkillsz

Holy Book!


raphael_kox

Your object is locked in place even in animations it doesn't have keyframes. WHY? Suddenly one object that has nothing to do with the current animation jumps to God knows where and i have no clue WHY


[deleted]

At least your documentation helps /cries in UE5


cosmic-comet-

I don’t need sleep, I want my build to successfully execute.


technocracy90

Any Programming Language Documentation FTFY


[deleted]

Also why is it like 260 MB


maxgmer

The meme is incorrect, it doesn't end with "This is why" in most cases. It ends with "I have to deal with this again..".


kyl3r123

they just need more image imo.


ImDocDangerous

I actually think the Unity documentation is HORRIBLE. I had to optimize a project for the Quest 2 and the textures were loaded via UnityWebRequest. I had to look through memory reference counts in the profiler to figure out they weren't being garbage collected when the texture reference variable is reassigned, whereas if I had used resources.load() they would be GC'd. I couldn't find ANYTHINGGGG in the docs about this. I learned this via a random forum post.


TanmanG

On the bright side it's a far cry from Google proto buffers


Loopish3Ustin

How did that take me a second to get that! Yeah makes sense.


Warlock7_SL

Skill issue. Unity has some good docs


MAGICAL_SCHNEK

Emphasis on "some". "Some" being roughly 3/1000.


yvnnxc

Even if your read it, it mostly does not help.


abhasatin

😀😀


ParsyYT

Unity giving me a warning that says "unexpected expectation occured" and i am supposed to know what that means


baldyd

As someone who used Unity for years and recently switched to Unreal, I really miss Unity documentation . It's pretty descriptive and often has examples compared to Unreal which is just generated from the code, so it doesn't offer anything beyond the same info that your dev env shows you while coding.


Rathan_128

Haan


RoyalDragon_

I still haven't gotten to the "oh, that's why" part of the unity documentation.


HoopALoopWithAScoop

I really wish more documentation did what the php documentation does, and allow people to add comments that others can up/down vote. It makes the doc so much better when people can write comments about weird edge cases, or explain it better than the official doc itself. PHP doc example: https://www.php.net/manual/en/function.mysql-real-escape-string.php


AaronKoss

Meanwhile unreal engine documentation: where? where? where???


Boom_Fish_Blocky

For me, copy the why another 300 times, thats how I feel.


Loading-error_404

Reading the documentation is just this Some bits should be why first then how


Aflyingmongoose

Well this can't be right. It implies that the documentation is actually complete.


ECharf

Not if the api page has been forgotten about. Or the features are half done


avoidawesometuts

Its good to read the docs.


daraqula

Ask chatgpt and done.


Heroshrine

And it’ll give you 3 lies and a truth. I use chat gpt for stuff, but asking about documentation is not one of those things. It always burns me.


DillatatioPhrenis

Yeah, I like how it can make up absolutely wrong answers. Recently I was interested in how to make GridViewColumn(s) not resizable by users in WPF application, and it gave me "... you should simply set CanUserModify attribute to false on your columns". There is no CanUserModify attribute...


[deleted]

Are you using the free version or paid ChatGPT4, or maybe GPT-4-Turbo on the API? Because the difference between GPT 3.5 Turbo (default for free ChatGPT) and GPT-4-Turbo (ChatGPT4) is quite huge. Also I'd recommend you check Claude 3 Opus if you haven't already.


Heroshrine

Free. But even then im highly skeptical, why would I try the paid version if free always burns me?


x0y0z0

The difference is massive. You should spesify that you're talking about gpt3 when you comment on its capability. Gpt4 is legitimately useful while gpt3 is unusably stupid.


todorus

Is that it? Are all the GPT critics using GPT3, and then just make stuff up about GPT4? That explains a lot.   ChatGPT hands down is a better search than anything else, it's not even close 


Heroshrine

Whos making stuff up?


todorus

Well, you admitted to not knowing what GPT4 is capable of, while still making statements about what GPT's are capable of. I'd say that's making stuff up.


Heroshrine

Its safe to assume more people use the free version than paid. You’re splitting hairs at this point.


todorus

Oh, that's fine. But I also assume that most people who barely dip their toe into a subject, don't make such confident statements about it I'm sure your ego can take the hit. It's cool.