Search Unity

Will there be a Unity UI Line Renderer?

Discussion in 'UGUI & TextMesh Pro' started by TechDevTom, Mar 12, 2015.

  1. TechDevTom

    TechDevTom

    Joined:
    Oct 21, 2011
    Posts:
    33
    Hi fellow devs,

    As someone who works with creating UI's a lot for games and apps for mobile devices I could see a UI Line Renderer being quite useful.

    I'm currently creating a graph inside of Unity3D 4.6.2 and am having a major issue when it comes to creating curves using the current LineRenderer component. Now, before anyone suggests using a plugin, I really want to try and avoid that if possible. I realise that there are plugins such as Vectrosity that create curves for you, but I've already gotten past that stage. I have my curves already and they're great!

    In the graph I am creating there are masks, as the graph doesn't fill the whole screen and you can scroll through the data through the X axis. Please see the attached image for a general idea of what's going on. The red box represents the masked area of my graph, so everything outside of that should be invisible and is.. apart from the curves drawn by the LineRenderer, as they are not an element of the new Unity UI. This for me is a problem and, to be honest, graphs and charts are very "UI" so perhaps Unity should not only look into implementing a UI LineRenderer but also a set of UI Graph components. What do you think?

    Blinx_CurvesEscapingMask.jpg

    Anyway, if anyone has any suggestions that might resolve my problem for now I'd be glad to hear them, if I have to resort to using plugins I will but I would rather solve this myself if possible. I also don't want to use multiple cameras to render different layers as that will end up increasing my draw calls (which won't be massive in 2D but still) and I may have multiple graphs in the scene, resulting in the use of multiple cameras.

    It would be interesting to see whether other people would like built-in UI graph elements too, so do post your thoughts! Cheers devs =D
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
  3. TechDevTom

    TechDevTom

    Joined:
    Oct 21, 2011
    Posts:
    33

    Hmmm, interesting, I will take a look at possibly creating my own then. I was not aware that you could make your own UI components, that's quite brilliant, although I'm not sure how to go about getting started with something like this so if anyone has any advice on such work I'd appreciate it. I'll go take a look around on the forums and google for advice on such things. Thanks fffMalzbier!

    Keep the suggestions coming and do say so if you think a Unity UI Graph component set/kit might be a good idea!
     
  4. Democide

    Democide

    Joined:
    Jan 29, 2013
    Posts:
    315
    I have no suggestions on how to do this, but if you build your own line renderer, I'd love to grab it :)

    Also in regards to your graph above: I'm assuming that are linerenderers with lots of points or how did you build the curves?
     
  5. TechDevTom

    TechDevTom

    Joined:
    Oct 21, 2011
    Posts:
    33
    If I manage to build one then I will try and make it available to the public, but I will be building it for the studio I work at, so it may go on the Asset store for a small fee as the tool will belong to the studio and not myself.

    Yes, for the above curves I am using the LineRenderer component attached to an empty GameObject. I then create a Vector3 array and fill it with the co-ordinates of the round data points. I then use a very useful script for drawing curves that I found here by Fernando Zapata here: http://wiki.unity3d.com/index.php/Interpolate

    However, if you are coding in c#, there is a little bit of a problem with the c# version of the code there that I have made the author aware of. Instead of using "IEnumerator" for such things as the "NewCatMullRom" function, he has used "IEnumerable" which unfortunately does not do anything and gives the user errors. If you use the c# script at the following site, simply change the "IEnumerable" part of a function like "NewCatMullRom" to "IEnumerator" and it'll work fine. Alternatively, just call the JS version from your c# script.

    At the moment I've had to use a second camera and an alpha mask material applied to some 3D planes to hide the lines generated with the LineRenderer. I am looking into making my own basic UI LineRenderer though, but no promises!
     
  6. Ramcat

    Ramcat

    Joined:
    Aug 16, 2014
    Posts:
    95
    Uh, yeah, who wouldn't want this!
     
  7. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    If you do build it, consider adding it to the UI Extensions bitbucket repo with all of the other fabulous community contributions :D (link in sig)
     
  8. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    mitaywalle likes this.
  9. losingisfun

    losingisfun

    Joined:
    May 26, 2016
    Posts:
    36
    I know it's been five years but you can use the LineRenderer Component for UI if you set your Canvas Render mode to World Space.

    But you'll need to make use of Sorting Layers and Sorting orders. Make a new Sorting Layer on top of everything else, just for your UI. Set your line renderer component sorting order to +1 of whatever you want it to be on top of and make sure its on the same (or higher) Sorting Layer to your Canvas.

    Hope this helps someone.
     
    coolcreator1 likes this.
  10. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    fffMalzbier likes this.
  11. Radishmouse4431

    Radishmouse4431

    Joined:
    Dec 11, 2021
    Posts:
    2
    Lowfeye likes this.