Why is Vector2.Abs() in VisualScripting package for unity?

Just wanted to know the answer to this question. I’m really curious; shouldn’t Vector2.Abs() be included by default? Also when I compile does code from the VisualScripting library compile?

Because it’s a package in your project. If you don’t use it, remove it

1 Like

You got your question backwards, that’s why DevDunk gave you the straight forward answer. You don’t want to know why the “Abs” function is in Vector2 in the VisualScripting package, because the answer is of course: “Because it’s useful”.

The actual question you’re indirectly asking is why does the Vector2 struct doesn’t have an Abs function. The answer is quite simple: You rarely need to take the absolute of a Vector’s components and if you really need to do that, you just take the abolute of the individual components manually. In scripting that is easy to do, in visual scripting you can only do what you have nodes for. You will find several convenient nodes in the visual scripting package that do not exist as functions to normal scripting because they are rare edge cases that can be solved with normal scripting easily.

You can think of infinite methods which could be useful in some edge cases, however that doesn’t mean Unity will add hundreds or thousands of methods to the Vector2 struct. Unity’s mathematics package aims for compatibility with shader code. Here you will have countless of utility functions which also work on float2, float3, float4 types which includes abs.

1 Like

Nope!

It does get reloaded, though, which happens after a compile, so having it in the project adds to the amount of time it takes for Unity to become responsive again after a code change - and how long it takes to enter play mode if fast enter play mode is off. This will be the case until after the CoreCRL switch ships - hopefully for Unity 7.

So if the real question underlying your question is “is it worth it to include the entirety of the Visual Scripting package just so I can have the Vector2.Abs function and other related utility functions”, the answer is no, not at all.

The functions are just extension methods, so if you want them, but not visual scripting, you can just find the Vector2Extensions class inside of Visual Scripting and copy it to your Assets folder, and then get rid of the package. Then you just reload the code you care about.

4 Likes