Having trouble deleting an InstantiateAsync object
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 25/100
Línea de trabajo
Start by reproducing the issue in the Unity AR sample and trace OnImageUpdated and OnImageAdded. Inspect the Addressables.InstantiateAsync, Release, and ReleaseInstance calls around target and curobject, then verify that changing the detected image removes the previous instance before the new asset is created and parented.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi,
I have an AR App where when an Image gets detected, it should Instantiate an AssetReference that image is associated with.
But I have another method where if a new Image is detected, I want to first delete the previously instantiated AssetReference, and then instantiate the AssetReference associated with the new Image.
Here is my code:
`
public class MultiTrackedImageManager : MonoBehaviour
{
public static MultiTrackedImageManager Instance { get { return instance; } }
private static MultiTrackedImageManager instance;
private ARTrackedImageManager m_TrackedImageManager;
private GameObject curobject;
private string PREFABFOLDER = "Prefabs/";
AssetBundle myLoadedAssetBundle;
[SerializeField]
private string imageName;
private GameObject prefabToLoad;
public List<MultiTrackedImage> Images = new List<MultiTrackedImage>();
// Addressables necessities for test
GameObject target;
private Vector3 spawnPosition;
GameObject testObj;
private void Awake()
{
//if (instance != null) { Destroy(instance); }
instance = this;
m_TrackedImageManager = GetComponent<ARTrackedImageManager>();
curobject = null;
spawnPosition = Vector3.zero;
}
void OnEnable()
{
m_TrackedImageManager.trackedImagesChanged += OnTrackedImagesChanged;
}
void OnDisable()
{
m_TrackedImageManager.trackedImagesChanged -= OnTrackedImagesChanged;
}
void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
{
foreach (var trackedImage in eventArgs.updated)
{
OnImageUpdated(trackedImage.referenceImage.texture.name, trackedImage.name, trackedImage);
}
foreach (var trackedImage in eventArgs.added)
{
OnImageAdded(trackedImage.referenceImage.texture.name, trackedImage.name, trackedImage);
}
}
public void OnImageUpdated(string textureName, string name, ARTrackedImage m_ARTrackedImage)
{
for (int i = 0; i < Images.Count; i++)
{
//if we have a match for the object and we have regained tracking and the current object is not the one for the trigger we just found
if (m_ARTrackedImage.trackingState == TrackingState.Tracking)
{
//this checks to make sure we are tracking the right image target
if(!string.Equals(Images[i].target.name, textureName)) { continue; }
//this checks to see if our current object is equal to the name of the image target so we don't delete and duplicate
if (string.Equals(curobject.name, Images[i].target.name)) { continue; }
//for some reason we are getting updates from non visible targets
if (curobject != null) { Destroy(curobject);}
GameObject go = GameObject.Find(name);
//Instantiate the prefab with the position of go
var addresableTarget = Addressables.InstantiateAsync(Images[i]._prefabReference, go.transform.position, Quaternion.identity);
if(target != null) {Addressables.Release(target); Addressables.ReleaseInstance(addresableTarget); }
target = addresableTarget.Result;
curobject = target;
curobject.name = Images[i].target.name;
TextManager.s.txtContent1 = Images[i].txt1 == "" ? " " : Images[i].txt1;
TextManager.s.txtContent2 = Images[i].txt2 == "" ? " " : Images[i].txt2;
TextManager.s.ResetText();
Images[i].go = go;
target.transform.rotation = go.transform.rotation;
target.transform.SetParent(go.transform);
target.transform.localPosition = Vector3.zero;
}
}
}
public void OnImageAdded(string textureName, string name, ARTrackedImage m_ARTrackedImage)
{
//PrefabManager.s.ClearPrefabs();
for (int i = 0; i < Images.Count; i++)
{
if (string.Equals(Images[i].target.name, textureName) && Images[i].go == null)
{
//Destroy the existing AR Animation
if (curobject != null) { Destroy(curobject);}
GameObject go = GameObject.Find(name);
//Instantiate the prefab with the position of go
var addresableTarget = Addressables.InstantiateAsync(Images[i]._prefabReference,
go.transform.position, Quaternion.identity);
if (target != null) { Addressables.Release(target); Addressables.ReleaseInstance(addresableTarget); }
target = addresableTarget.Result;
curobject = target;
curobject.name = Images[i].target.name;
TextManager.s.txtContent1 = Images[i].txt1 == "" ? " " : Images[i].txt1;
TextManager.s.txtContent2 = Images[i].txt2 == "" ? " " : Images[i].txt2;
TextManager.s.ResetText();
Images[i].go = go;
target.transform.rotation = go.transform.rotation;
target.transform.SetParent(go.transform);
target.transform.localPosition = Vector3.zero;
}
}
}
`
- Lenguaje dominante
- C#
- Estrellas
- 1.5k
- Forks
- 303
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Unity-Technologies/Addressables-Sample
-
ODR doesn't seem to work anymoreAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 32/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
Unity-Technologies/Addressables-Sample#98 · 3 comentarios ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Unity-Technologies/Addressables-Sample#94 · 2 comentarios ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 30/100
Unity-Technologies/Addressables-Sample#90 · 1 comentario ·
Todos los issues de Unity-Technologies/Addressables-Sample
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
stryker-mutator/stryker-net#3892 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
MobiFlight/MobiFlight-Connector#3419 ·
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
-
`Source` with an `avares://` URI and a `#fragment` throws instead of scrolling to the anchorAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Kryptos-FR/MarkView.Avalonia#105 ·
Los mantenedores suelen responder en 1 día
-
[辞書]Abierto提案 辞書
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día