Prefab name in Project does not match Inspector

Hi All,

The prefab name in inspector has the name I assigned to a prefab’s instance at runtime. When I try to change name in Inspector, it reverts back to name I assigned at runttime.

Run time name: “Ping at: 53 from: SonarTransmitter”.

Name of prefab: “SonarWaveSphere”.

Thanks

Make sure the script that names the prefab at runtime is not running in Edit Mode. In C#, this would be [ExecuteInEditMode] . In UnityScript this would be @script ExecuteInEditMode()

Make sure this is NOT being used. Go here for more info.

Also, usually you don’t want to rename an actual asset, but instantiate a “clone” of a prefab and give that clone a name at runtime…

I mistakenly used the first solution in reference document.

     Instantiate(prefab, new Vector3(i * 2.0F, 0, 0), Quaternion.identity) as Transform;

As described by cluck47, I used the second solution that returns the instance.

		GameObject waveGO = (GameObject) Instantiate( sonarWavePrefab, // original : Object, 
			         transmitterPostion, // position : Vector3, 
			         transmitterRotation ); // rotation : Quaternion) : Object 
		waveGO.name =  "Ping at: " + Time.time + 
			        			" from: " + this.gameObject.name;
		SonarWave wave = waveGO.gameObject.GetComponent<SonarWave>();
		wave.startTimeInSeconds = Time.time;
		// wave to have energy of transmitter
		wave.energy = this.power;