- Home /
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
Your answer