Transforms as Start and End for line

  • updated
  • Declined

As an UX designer, I mainly use Shapes to draw lines between moving Objects/Prefabs/Transforms.

It would be a huge gain in productivity to just drag Prefabs to set the Start and End of the line, as an option.

Image 691

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
Built-in render pipeline
Freya Holmér creator
  • Declined

detecting transform changes in a safe way from an API standpoint is nontrivial, so unfortunately I won't be adding support for this. you can, however, make a script that effectively does this for you! This might be useful in your use case:

using Shapes;
using UnityEngine;

[RequireComponent( typeof(Line) )] [ExecuteAlways]
public class LineBetween : MonoBehaviour {

public Transform start;
public Transform end;

Line line;
Line LineComp => line != null ? line : line = GetComponent<Line>();
void OnValidate() => UpdateLine(); // update when changing something in the inspector
void Update() => UpdateLine(); // update every rendered frame

// call this to make the line match the transforms:
public void UpdateLine() {
if( start != null && start.transform.hasChanged ) {
LineComp.Start = LineComp.transform.InverseTransformPoint( start.position );
start.transform.hasChanged = false; // note: this may interact badly with multiple scripts
if( end != null && start.transform.hasChanged ) {
LineComp.End = LineComp.transform.InverseTransformPoint( end.position );
end.transform.hasChanged = false; // note: this may interact badly with multiple scripts

Greg Madison

Thank you Freya :)