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.
  2. Dismiss Notice

Line Renderer - Getting parameters by scripting?

Discussion in 'Scripting' started by The-Spaniard, Jun 26, 2014.

  1. The-Spaniard

    The-Spaniard

    Joined:
    Jan 7, 2012
    Posts:
    149
    Hi All,

    I'm having a problem getting the parameters of a Line Renderer component - if I say, want to double the width of a lineRenderer, but I don't know the starting widths, there is no startWidth, or endWidth variables like there are for a trailRenderer. Is there something missing from the documentation, or does this feature not exist?

    Thanks for your help!
     
  2. The-Spaniard

    The-Spaniard

    Joined:
    Jan 7, 2012
    Posts:
    149
    Just wanted to bump this - I've got a work around, but it's pretty ugly.

    Is the inability to get Line Renderer parameters a gap in Unity's documentation, or a limitation of the feature itself?
     
  3. zaxvax

    zaxvax

    Joined:
    Jun 9, 2012
    Posts:
    220
  4. The-Spaniard

    The-Spaniard

    Joined:
    Jan 7, 2012
    Posts:
    149
    But those aren't accessible from a script: "this.lineRenderer.StartWidth" and "this.lineRenderer.startWidth" both give compile errors. (LineRenderer does not contain definition for "startWidth"...)

    The scripting reference page says "useWorldSpace" is the only accessible variable and the others are set by SetColors(), SetPositions() etc. But there are no GetPositions(), GetWidths() etc methods.

    If it is possible, what is the correct syntax to get the startWidth?
     
  5. zaxvax

    zaxvax

    Joined:
    Jun 9, 2012
    Posts:
    220
    Hmm right... seems to be write only.
    Pathetic behavior... maybe should make a bug report about this.
     
  6. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  7. The-Spaniard

    The-Spaniard

    Joined:
    Jan 7, 2012
    Posts:
    149

    Damn, how irritating. I'll file a bug report - it's possible to get them for trail renderers so it should be possible for line renderers too. Of course it is possible to cache the variable, but if you have multiple scripts acting on it, then you have to start passing that float between scripts, which is frankly, really ugly.

    Thanks for your help.
     
  8. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,731
    You can get line renderer settings using the bounds property. Maybe something like this might help with what you were trying to do. The following code will return the renderer line width.

    Code (CSharp):
    1. LineRenderer line = getComponent<LineRenderer>();
    2. float width = line.bounds.size.x;
     
  9. IAMBATMAN

    IAMBATMAN

    Joined:
    Aug 14, 2015
    Posts:
    272
    Damn, now you can't get either. What do I do?
     
  10. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    Now, you use .widthCurve (which is much more versatile, but does require that you know how to use AnimationCurves) and/or .widthMultiplier.
     
    Munchy2007 likes this.
  11. IAMBATMAN

    IAMBATMAN

    Joined:
    Aug 14, 2015
    Posts:
    272
    don't mind my last post. intellisense wasn't working making me think it didn't exist anymore :)