Making change to an instance of a prefab doesn't work...

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

Looks fine to me. Once you Instantiate an object, it’s not a prefab anymore. It’s just a regular gameObject. There are no special “I came from a prefab” rules. In other words “change to an instance of a prefab” isn’t an issue. You’re just changing a regular gameObject.

There’s probably just a bug somewhere else. Try the usual Debug stuff – make m_curPrefab public, Pause, and check it points to the right spot; add a color change line (something easy to spot); make a smaller test function, make, sure no other script are interfering.

But, comments: m_currentPrefab is a confusing name. Prefabs are what goes into an Instatiate. The item you get out isn’t a prefab.

Vector3.zero is a shortcut for new Vector3(0,0,0);. BUT, instead of setting size to 0, easier to SetActive(false).

I prefer transform.Find("path/name") to getChildByName (more precise.)

Instead of Resourse.Load, often easier to use public GameObject someThing; // prefab dragged here.