- Home /
Prefab instantiates with its components disabled
public class DeathCheck : MonoBehaviour
{
public GameObject paintBall;
public GameObject expEffect;
public GameObject newPlayer;
public AudioSource splatSound;
public Transform shotPoint;
public Transform spawnPoint;
public float ExpDeviation;
// Update is called once per frame
void Update()
{
if (Input.GetButton("Fire1"))
{
Death();
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "Deadly")
{
Death();
}
}
void Death()
{
Destroy(gameObject);
Debug.Log("Boom!");
splatSound.Play();
//Creates 20 balls with random rotations
for (int i = 0; i < 20; i++)
{
float dev = Random.Range(-ExpDeviation/2, ExpDeviation/2);
float rotZ = i * 18 + dev;
transform.rotation = Quaternion.Euler(0f, 0f, rotZ);
Instantiate(paintBall, shotPoint.position, transform.rotation);
}
//Explotion Effect
Instantiate(expEffect, shotPoint.position, transform.rotation);
Respawn();
}
void Respawn()
{
Instantiate(newPlayer, spawnPoint.position, Quaternion.identity);
}
}
Prefab's components are enabled All the clone's components are disabled
Answer by rxx1 · Feb 12, 2021 at 06:50 AM
This thread explains what the problem could be. I can't test it now but I'll update this comment when I do
https://forum.unity.com/threads/instantiating-a-prefab-makes-disables-all-components.278471/
Answer by Megaboy238 · Feb 10, 2021 at 08:51 PM
Prefabs can have their components etc enabled on the surface but if you go into the Edit of the prefab they can be disabled there and that's the state they will enter the game. Double click the prefab to edit and check there.
Do you take the prefab from the Hierarchy or from Assets, it may not make a difference but from the Hierarchy it might be trying to Instantiate the destroyed game prefab as so thinking it should be in that state Null. If not try drag drop prefab from Assets to inspector. $$anonymous$$aybe worth a try
I take it from assets. the image above shows the inspector of the prefab
Answer by murgonen · May 16 at 03:57 AM
For me, this happens when I think I drag-n-dropped a prefab reference to the field from the project hierarchy, but instead dragged it from the scene hierarchy.
It's very subtle thing, prefab changes propagate to the object and it seems identical in the Inspector, unless you click on on prefab field to see which one it highlights.
Your answer
![](https://koobas.hobune.stream/wayback/20220613024942im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Instantiated prefab not working 1 Answer
Destroying and instantiating parent GameObject 0 Answers
How to check if a component is on an instantiated prefab? 1 Answer
Get child component of a prefab to reference with another prefab 1 Answer
Removing A Component From An Instantiated Prefab After X More Are Instantiated 1 Answer