-1

I am adding spheres at pointer clicked event but it seems that I am working on a virtual copy. I tried to see whether the destructor is called but it is not

I am adding spheres at pointer clicked event but it seems that I am working on a virtual copy or local copy. I tried to see whether the destructor is called but it is not for the object class I am using

com.microsoft.mixedreality.toolkit.foundation@f2323a9b7aec\Services\InputSystem\MixedRealityInputModule.cs

Modified MixedRealityInputModule.cs

    void IMixedRealityPointerHandler.OnPointerClicked(MixedRealityPointerEventData eventData)

I am pushing the spheres in a list and counting them , but it seems that the counter is always 0. static int spheresCount = 0; private static List spheres = new List(); public void CreateSphere(Vector3 center) GameObject sphereobj = GameObject.CreatePrimitive(PrimitiveType.Sphere);//Capsule sphereobj.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); sphereobj.transform.position = center; sphereobj.GetComponent().material = SphereYelllowMaterial; sphereobj.tag = "sphere_add_" + spheresCount.ToString();

spheresCount += 1;
spheres.Add(sphereobj);
Debug.Log(" " + System.Reflection.MethodBase.GetCurrentMethod().Name + " " + "spheres layer=" + sphereobj.layer);
Debug.Log(" " + System.Reflection.MethodBase.GetCurrentMethod().Name + " " + spheresCount);
Debug.Log(" " + System.Reflection.MethodBase.GetCurrentMethod().Name + " " + "sphere center=" + center.ToString());
Debug.Log(" " + System.Reflection.MethodBase.GetCurrentMethod().Name + " " + "sphere.layer=" + spheres[spheresCount].layer.ToString());
Debug.Log(System.Reflection.MethodBase.GetCurrentMethod().Name + " " + "sphere");
Debug.Log(" " + System.Reflection.MethodBase.GetCurrentMethod().Name + " " + spheresCount);// ----> not even shown

Am I missing a configuration? I tried marking the variables as volatile But still no improvement

private volatile static List<GameObject> spheres = new List<GameObject>(5);
static UInt16 spheresCount = 0;

enter image description here

enter image description here

cdruno
  • 1
  • 1
  • you dont seem to add your new sphere to the list, so the count wont go up, and the int just seems to be an int.. again nothing is updating it – BugFinder Aug 28 '23 at 15:46
  • Thank you for the answer. The adding took place. I did not add the line of code. So I had a separate script with class DrawSpheres I instantiated in com.microsoft.mixedreality.toolkit.foundation@f2323a9b7aec\Services\InputSystem\MixedRealityInputModule.cs Modified MixedRealityInputModule.cs When moving the content of that DrawSpheres - list and methods for drawing inside MixedRealityInputModule.cs, counting works perfectly. That class was singleton, the objects static. Saw also that the constructor&destructor were called multiple times https://i.stack.imgur.com/HyMnO.png – cdruno Aug 29 '23 at 15:22
  • Could someone tell me what could be the issue if I declare a singleton class and instantiate it within MixedRealityInputModule.cs OnClickEvent -it seems that I work on a local copy and the list does not seem to be updated When I move the code of the class it works fine , but no longer benefit from the OOP/OOD and reusability – cdruno Aug 30 '23 at 10:38

0 Answers0