Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question What is the difference between math/generic and math/scalar

Discussion in 'Visual Scripting' started by attractiveminds, Oct 5, 2022.

  1. attractiveminds

    attractiveminds

    Joined:
    Nov 19, 2020
    Posts:
    3
    i want to use a basic math function "add" and it gives me a few options to use "add in math/generic" and "add in math/scalar" just wondering what the difference is? TIA
     
  2. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    An easy way to think of it is like this:

    Generic will work using multiple types of inputs. for example a vector 3 can be multiplied by a float using a generic but not scalar. Scalar offers a text input box to type a number in. As where the Generic has no text input box. you'll notice how the connection wires are not the same colors to help indicate the type of data too


    here you can see i'm multiplying a Vec3 by an int. but can't even connect that to a scalar
    Capture.PNG
     
    Last edited: Oct 6, 2022
  3. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    166
    Generic input an object type and can handle some kind of auto conversion when you have different types, while scalar is forcing you to use the good type of data.
     
    REDACT3D_ likes this.
  4. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Beauty.
    does the auto conversion cost more performance points?
    Why wouldn't one want to just use generic for everything?
    aside from getting to use that good type of data for compatibility
     
  5. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    166
    - I need to validate, but the conversion from typed to generic could generate some garbage collection issues based on how C# work.
    - Like any transformation, yes, you should expect some performance lost, but should not be significant enough to bother.
    - We will need to profile, to be able to answer completely this question.

    - Scalar have input fields directly on the nodes and le you type hardcoded value within the node instead of linking literal nodes.
    - Scalar give you the control over the outputted data type.
    - Scalar should not give you garbage collection issue.[/QUOTE]
     
    REDACT3D_ likes this.
  6. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    [/QUOTE]


    Perfect, that helps a lot. Thanks!

    Right, as with most performance related questions; I guess it could best be answered for my particular setup via the Profiler. Have to admit I don't use it as much as I should. Interesting point on controlling the value output.

    It could help to change the icon on the node or some kind of visual identification, as apart from the text input box the two nodes look very similar when stuff is hooked in.

    For example: which one of these two nodes is the Scalar?
    Capture.PNG

    //Hint
    Capture.PNG

    It's the one with the tiny blue dot
     
  7. ericb_unity

    ericb_unity

    Unity Technologies

    Joined:
    Nov 24, 2017
    Posts:
    166
    If we make the math operators like it was in DOTS VS, that won't be an issue in the future.

    But yes as of what we have today, it is something pretty hard to see and may bring other kind of issues than performance issues. I to debug some issues related to generic operators and AOT prebuild not working with them not so long ago. (This bug was fixed and pushed). Finding why stuff was behaving wrongly only in WebGL and not in the editor + windows build, was pretty already challenging, but validating that the generic operators were the only issue in the project by replacing all operators by the ones using the good data type was even harder.

    You can at least for now use the node finder, to find operators types in graphs.
    https://assetstore.unity.com/packag...node-finder-for-unity-visual-scripting-205655

    For profiling, it will be harder as the current state of the tool won't show you what take time in your graph.
     
  8. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Oh geez, are you saying that the Generic will not work correctly (or bake out? correctly) with WebGL currently? Or that you couldn't even find it inside the graph? or both?

    handy to know if i'm going to throw together some more videos as planned. I know a lot of guys who may want to work with that and if I can make a choice in what I show as to not mislead or confuse new users that would be beauty. lol Although I'm sort of thinking about the timeline on updates to VS but can always remove irrelevant information.

    The node finder looks neat. I'll have to give that one try. thanks for pointing it out

    It would be sweet to have some kind of profiler as a node, kind of like a little oscilloscope to plug-in values. with gate triggers and all that to time responses or just visualize the data. although there's always issues with the scope introducing it's on draw on the system..

    could always do it old school with a high speed camera pointed at the screen to record the absolute delay lol
    cave man style.

    Not really looking to performance dragracer, only achieve noticeable results that 90% of the players would notice on the first time around kinda thing
     
    Last edited: Oct 12, 2022