Topic locked

Resetting the Smart Terrain Tracker and terrain mesh

July 1, 2014 - 3:50am #1
Trying to Start / Reset smart terrain... Recieve a null reference when using mTracker.Start / Reset / StartMeshUpdate etc...

private SmartTerrainTracker mTracker;

void Start ()

{

mTracker = TrackerManager.Instance.GetTracker<SmartTerrainTracker>();

mTracker.Start();

}

void Start ()

{

mTracker = TrackerManager.Instance.GetTracker<SmartTerrainTracker>();

mTracker.Start();

}

Gives me "NullReferenceException: Object reference not set to an instance of an object"

Any ideas?

 

Resetting the Smart Terrain Tracker and terrain mesh

July 4, 2014 - 2:24am #3

Ah cheers Alessandro, realised that was the issue the other day! Thanks for your help though. 

Resetting the Smart Terrain Tracker and terrain mesh

July 3, 2014 - 1:06pm #2

Hi,

you are calling mTracker.Start() without checking if mTracker is null or not. This is a basic programming error.

Also, in this case mTracker is null because the Tracker has not been initilalized yet when you are in the Start() method of your script;

if you want to be sure that the Tracker has been initialized, you should implement a ISmartTerrainEventHandler interface, register it in SmartTerrainBehaviour and use the OnInitialized() method as a callback in which you can put your code.

Reading the Smart Terran Developer Guide and more in general the Vuforia Developer Guide should put  you on track; the Smart Terrain sample project is also a helpful resource, where you can study the sample code and learn how to optimally use the API.

See also the API reference:

https://developer.vuforia.com/resources/api/unity/class_smart_terrain_abstract_behaviour

https://developer.vuforia.com/resources/api/unity/interface_i_smart_terrain_event_handler

 

 

Topic locked