Include the following details (edit as applicable):
- Issue category: ARDK Documentation / Unity Example Package
- Device type & OS version: Android
- Host machine & OS version: Windows
- Issue Environment : On Device
- Xcode version:
- ARDK version: v2.0.0
- Unity version: 2020.3.30f1
Description of the issue:
I’m using the Image Detection Example Manager for my project. How does one go about removing the instantiated prefab when the image is out of the camera’s view?
I tried saving the plane as a global variable and removing it using Destroy() under OnAnchorsRemoved(), which did not work.
GameObject newPlane;
private void OnAnchorsAdded(AnchorsArgs args)
{
foreach (var anchor in args.Anchors)
{
if (anchor.AnchorType != AnchorType.Image)
continue;
var imageAnchor = (IARImageAnchor) anchor;
var imageName = imageAnchor.ReferenceImage.Name;
newPlane = Instantiate(_plane);
// instantiated = newPlane;
newPlane.name = "Image-" + imageName;
SetPlaneColor(newPlane, imageName);
_detectedImages[anchor.Identifier] = newPlane;
UpdatePlaneTransform(imageAnchor);
}
}
private void OnAnchorsUpdated(AnchorsArgs args)
{
foreach (var anchor in args.Anchors)
{
if (!_detectedImages.ContainsKey(anchor.Identifier))
continue;
var imageAnchor = anchor as IARImageAnchor;
UpdatePlaneTransform(imageAnchor);
}
}
private void OnAnchorsRemoved(AnchorsArgs args)
{
foreach (var anchor in args.Anchors)
{
if (!_detectedImages.ContainsKey(anchor.Identifier))
continue;
Destroy(_detectedImages[anchor.Identifier]);
// destroyPlane();
_detectedImages.Remove(anchor.Identifier);
Destroy(newPlane);
}
}