"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

Dynamically assigning game objects as children of VuMark at runtime in Unity

I am working on an AR application for Android in Unity and as I will only know what objects I want to be tracked and displayed at runtime, I am currently trying to assign these objects (which are created dynamically) as the child of VuMark at runtime accordingly.

However, nothing shows up when I test this in the Unity editor by showing the VuMark marker I have in front of my webcam! Strangely enough, if I manually instantiate an object (like a cube) at the hierarchy view as the child of VuMark, the cube would show up! I am really at my wits' end as to what I can do to make my dynamically created objects show up, since what my code is doing is essentially the same as what I did manually. Here's the code I used to add the dynamically created object as child of VuMark:

void Start()
{
  GameObject vuMark = GameObject.Find("VuMark");

  GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
  
  // "material" is a public instance variable I have outside of this snippet
  cube.GetComponentInChildren<MeshRenderer>().material = material;
  cube.transform.parent = vuMark.transform;
}

Any suggestions on what I should try next would be much appreciated! Thanks!

Have u tried using Instanciate() for instanciating a Prefab instead of creating a primitive?

 

https://docs.unity3d.com/ScriptReference/Object.Instantiate.html

I've just tried using prefab, and soon realised that the problem was the primitive created in code was too big/not a unit cube - it was instead 10x the unit cube - so the camera was inside the cube and as a result the object was not visible... silly me.