• 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 iboussah · Jun 02, 2016 at 04:02 PM · scripting beginnerbuild error

Bug on first play or after building

Hi, I'm working on a project with ARToolkit (a package for augmented reality) I have a problem with my project : it works fine as many times as I want until I build an APK for android. Just after that, it doesn't work on Unity (and it doesn't work on the application installed from the apk) My scene is a basic scene of ARToolkit that works perfectly. The only modification I made was to attach a script to create manually gameObjects. Here is the script :

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class MarkersCreator : MonoBehaviour {
     const int N=10;
 
     string[] names=new string[N];
     ARMarker[] markers=new ARMarker[N]; //ARMarker is a GameObject of ARToolkit
     ARTrackedObject[] tracked = new ARTrackedObject[N]; //ARTrackedObject is a GameObject of ARToolkit
 
 
 
 
     // Use this for initialization
     void Start () {
         GameObject root = GameObject.Find ("Scene root"); //This GameObject exists in my scene
 
         names [0] = "name0";
         names [1] = "name1";
         names [2] = "name2";
         names [3] = "name3";
         names [4] = "name4";
         names [5] = "name5";
         names [6] = "name6";
         names [7] = "name7";
         names [8] = "name8";
         names [9] = "name9";
         
         
         for (int i = 0; i < N; i++) {
             markers [i] = gameObject.AddComponent<ARMarker> ();
             markers [i].Tag = "marker"+i.ToString();
             markers [i].MarkerType = MarkerType.NFT;
             markers [i].NFTDataName = names [i];
 
             GameObject markerscene = new GameObject ("MarkerScene"+i.ToString());
             markerscene.layer = 9;
             markerscene.transform.parent = root.transform;
             markerscene.transform.localRotation = Quaternion.Euler (Vector3.zero);
 
 
 
 
 
             tracked [i] = markerscene.AddComponent<ARTrackedObject> ();
             tracked [i].MarkerTag = markers [i].Tag;
 
             Debug.Log ("cube créé");
 
             GameObject cube = GameObject.CreatePrimitive (PrimitiveType.Cube);
             cube.layer = 9;
             cube.transform.parent = markerscene.transform;
             cube.transform.localPosition = new Vector3 (0, 0, -0.02f);
             cube.transform.localRotation = Quaternion.Euler (Vector3.zero);
             cube.transform.localScale = new Vector3 (0.04f, 0.04f, 0.04f);
 
 
         }
 
     }
 
 }
 

I also noticed that it doesn't work when I open Unity for the first and press play. I have to remove my script and attach again and it works (I have to make the same manipulation after building an apk).

I really don't understand. It must come from my script but why does it work sometimes ?

Did it happen yet to someone ? Does anyone has a clue ?

Thank you for your answers.

Ilyès

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

creating prefabs in array 2 Answers

Can you trick a Ui Button that it is being clicked with code? 3 Answers

Is it ok to use transform.Rotate with a rigidbody that will use force also 2 Answers

Make character follow mouse 3 Answers

PlayerMovement and PlayerShooting Scripts 1 Answer


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