Hi all, i have a problem for wich i cannot find any solution online :
I am trying to make change to a child of a prefab that is instantiated by code, but every change i make is not taken into account. For example i tried turning of the mesh renderer, changing scale, position, etc.
Here is the method creating the prefab :
private GameObject InitPrefab (string a_prefabName, GameObject a_prefabParent = null)
{
GameObject t_prefab = Instantiate (Resources.Load (RA_PREFAB_PATH + a_prefabName, typeof(GameObject))) as GameObject;
if (a_prefabParent != null) {
t_prefab.transform.parent = a_prefabParent.transform;
}
return t_prefab;
}
This does work, and my prefab is created correctly on stage ( the return value is referenced in m_currentPrefab)
Here is the method trying to actually make change to some of the prefab children (named : layer0, layer1 and layer2)
private void SwipeToNextPrefabLayer ()
{
int t_layerIndex = m_currentLayerNum + 1;
if (t_layerIndex <= m_currentARScenario.TotalLayers - 1) {
GameObject t_layer = m_currentPrefab.transform.GetChildByName ("layer" + t_layerIndex).gameObject;
if (t_layer == null) {
Console.Log ("No child found with name : " + "layer" + t_layerIndex);
return;
} else
Console.Log ("Currently swiping layer " + t_layer.name);
//t_layer.GetComponent<MeshRenderer> ().enabled = false;
t_layer.transform.localScale = new Vector3 (0f, 0f, 0f);
m_currentLayerNum++;
} else
Console.Log ("Last swipeable layer reached!!!");
}
GetChildByName is just an extension for Transform, which works too, i do have the child “layer0” returned and can even log its name, but if i try t_layer.transform.localScale = new Vector3 (0f, 0f, 0f);
i cannot see anything change!?
Am i forgetting something? It seems my modifications made by code at runtime on an instance are not kept or taken into account…
Any help is welcome, thanks all!
UPDATE : Finally, it was the prefab itself, somehow it got corrupted, and as soon as i recreated it, it worked!
Jim