Thanks for posting! Below are my thoughts on how you might solve this.
If you want objects to spawn on all AR planes that you scan, do the following in Unity:
- In the Project window, copy Packages / Litho Beta SDK / Core / Prefabs / AR / ARPlane into your Assets folder - let’s call this copy Assets / SpawnerARPlane
- In the Hierarchy window, select ARSessionOrigin
- In the Inspector window, look for the component AR Plane Manager on the ARSessionOrigin object - this will have a Plane Prefab variable
- Drag your new SpawnerARPlane prefab from the Project window to the Inspector window, and drop it into the Plane Prefab field of the AR Plane Manager component
- From the Project window, open your new SpawnerARPlane prefab for editing by double-clicking it
- Attach your Spawner script to the SpawnerARPlane prefab using the “Add Component” button in the Inspector window
- Now when a plane is detected, SpawnerARPlane instances will be used to represent it, meaning each plane will also now have the Spawner script attached to it, and hence will start spawning objects on itself.
- To ensure the spawned objects only appear within the bounds of the AR plane, you can use
GetComponent<ARPlane>().boundary in your Spawner script to retrieve a list of
Vector2 objects which describe the perimeter of the plane. You can then find the minimum and maximum x and y values by looping through all of those boundary points - use these min and max values for generating the random point.
- To make it more accurate, you can use an algorithm to check whether the generated random point is within the boundary, and generate a new one if it is not. Such an algorithm can be found from other sources, such as this one on StackOverflow: https://stackoverflow.com/a/14998816 (you’ll need to replace
- Note that it is recommended that you don’t change any of the scripts provided in the Litho Beta SDK package (e.g. WorldInterpreter) - they are accessible for modification, however any changes you do make may cause future package updates to break your project (as your code modifications will get replaced by the code in the updated package).
Excited to see what you’re making - let us know how you get on!