Is it possible to dynamically create a new PointGraph and assign the Root Transform?

Hi,

Is it possible to dynamically create a new PointGraph and assign the Root Transform?

At the moment I am starting with the basics, so I have already added a PointGraph manually, and trying to tell it which transform to use as the Root Transform. So far I have had no luck. Here is the code I have written so far:

`import Pathfinding;

var aStar : AstarPath;
var waypointsParent : Transform;

function Start()
{
waypointsParent = GameObject.Find(“WayPoints”).transform;
aStar = GameObject.Find("_A*").GetComponent(AstarPath);
aStar.pointGraph.AddRoot(waypointsParent);
}`

I get the error:
NullReferenceException: Object reference not set to an instance of an object

I can see in the inspector that both the aStar component and the waypointsParent have been found.

Where am I going wrong?

Thanks

Never mind, after further digging around and looking at as many unityscript based questions I could find, I managed to work it out. For those who are still learning all aspects of Unity and A* this might help:

`import Pathfinding;

var aStar : AstarPath;
var waypointsParent : Transform;
var pointGraph = new PointGraph();

function Start()
{
waypointsParent = GameObject.Find(“WayPoints”).transform;
aStar = GameObject.Find("_A*").GetComponent(AstarPath);
aStar.astarData.AddGraph(pointGraph);
pointGraph.root = waypointsParent;
}

function Update()
{
pointGraph.Scan();
}`

Of course I do not recommend having the pointGraph.Scan running all the time in the Update function and it would be best to call when needed ect. I just put it there to show it working.

Good luck!

Great you managed to figure it out. And yes, it is much more performant to just call Scan right after you have constructed the graph in Start().