Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by unity_al0Xy8XVy9R3qg · Jul 13, 2020 at 11:16 AM · augmented-realityaugmented reality

ARCore augmented image - The Object you want to instantiate is null

I want to create a app that will recognise images and add different objects to them. I'm working off the Google augmentedimage example.

I have two objects sphere and a cube. Both are prefabs and both have AugmentedImageVisualizer assigned to them.

AugmentedImageExampleController separates images as it should but when AugmentedImageVisualizer wants to enable visibility for cube or sphere it fails with error The object you want to instantiate is null.

Here are scripts

 public class AugmentedImageExampleController : MonoBehaviour
     {
         /// <summary>
         /// A prefab for visualizing an AugmentedImage.
         /// </summary>
         public AugmentedImageVisualizer[] AugmentedImageVisualizerPrefab;
  
         /// <summary>
         /// The overlay containing the fit to scan user guide.
         /// </summary>
         public GameObject FitToScanOverlay;
  
         private Dictionary<int, AugmentedImageVisualizer> m_Visualizers
             = new Dictionary<int, AugmentedImageVisualizer>();
  
         private List<AugmentedImage> m_TempAugmentedImages = new List<AugmentedImage>();
  
         /// <summary>
         /// The Unity Update method.
         /// </summary>
         public void Update()
         {
             // Exit the app when the 'back' button is pressed.
             if (Input.GetKey(KeyCode.Escape))
             {
                 Application.Quit();
             }
  
             // Get updated augmented images for this frame.
             Session.GetTrackables<AugmentedImage>(
                 m_TempAugmentedImages, TrackableQueryFilter.Updated);
  
  
  
             // Create visualizers and anchors for updated augmented images that are tracking and do
             // not previously have a visualizer. Remove visualizers for stopped images.
             foreach (var image in m_TempAugmentedImages)
             {
                 int i = image.DatabaseIndex;
                 AugmentedImageVisualizer visualizer = null;
                 m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer);
 
                 Debug.Log(image.DatabaseIndex);
                 if (image.TrackingMethod  == AugmentedImageTrackingMethod.FullTracking && visualizer == null)
                 {
                     // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                     Anchor anchor = image.CreateAnchor(image.CenterPose);
                     Debug.Log("Anchor created");
  
                     visualizer = (AugmentedImageVisualizer)Instantiate(
                         AugmentedImageVisualizerPrefab[i], anchor.transform);
                     visualizer.Image = image;
                     m_Visualizers.Add(image.DatabaseIndex, visualizer);
                 }
                 else if (image.TrackingMethod  == AugmentedImageTrackingMethod.NotTracking && visualizer != null)
                 {
                     m_Visualizers.Remove(image.DatabaseIndex);
                     GameObject.Destroy(visualizer.gameObject);
  
  
                 }
              
             }
  
             // Show the fit-to-scan overlay if there are no images that are Tracking.
             foreach (var visualizer in m_Visualizers.Values)
             {
                 if (visualizer.Image.TrackingMethod  == AugmentedImageTrackingMethod.FullTracking)
                 {
                     FitToScanOverlay.SetActive(false);
                     return;
                 }
             }
  
             FitToScanOverlay.SetActive(true);
         }
     }

and Visualiser script

 public class AugmentedImageVisualizer : MonoBehaviour
     {
         /// <summary>
         /// The AugmentedImage to visualize.
         /// </summary>
           public AugmentedImage Image;
  
      
  
         public GameObject prefabToInstantiate;
  
         /// <summary>
         /// The Unity Update method.
         /// </summary>
         public void Update()
         {
             if (Image == null || Image.TrackingMethod != AugmentedImageTrackingMethod.FullTracking)
             {
              
                 prefabToInstantiate.SetActive(false);
  
                 return;
             }
 
             float halfWidth = Image.ExtentX / 2;
             float halfHeight = Image.ExtentZ / 2;
             prefabToInstantiate.transform.localPosition =
                 (halfWidth * Vector3.left) + (halfHeight * Vector3.back);
             prefabToInstantiate.SetActive(true);
  
         }
   
     }

I tried to solve the problem with instantiating it at start with Instantiate()

In visualizer but it still failed. Original example doesn't use it it just enables gameobject's visibility.

Screenshots:alt text Sphere and cube are the same: alt text

1.png (18.5 kB)
2.png (8.3 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gwuwer-mms · Jul 13, 2020 at 02:57 PM 0
Share

What is this for a ToolKit you are using? I would try to use ARFoundation. This is the new Unity standard.

avatar image unity_al0Xy8XVy9R3qg gwuwer-mms · Jul 13, 2020 at 05:49 PM 0
Share

Plain ARCore

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KirillKuzyk · Jul 14, 2020 at 05:36 AM

You can't Instantiate MonoBehavior separately from GameObject. Please Instantiate the whole GameObject and then call instantiatedGameObject.GetComponent();

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

145 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Time based Augmented Reality application 0 Answers

Is Unity 3D suitable for a furniture augmentation app? 1 Answer

What do you call image-marker recognition from device camera, without AR tracking. 0 Answers

Hololens: Share a WorldAnchor between individual apps 0 Answers

how can play many video with use menu in augmented reality,how to play many video with menu in augmented reality? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges