Instantiated Prefabs Not Showing Components

I have been looking around for about an hour now and can’t find anything like this with replies, so I figured I’ll give this a shot.

Essentially, my prefab won’t instantiate with expected components in runtime.


Below is my prefab within its folder in the assets section (with all the expected components & references attached):

And below is my prefab upon creation during runtime:


Below is the code I’ve used to instantiate the object:

public void InstantiateNewDog(Vector3 vector3, Quaternion quaternion, Transform transform, int dogType)
        {
            GameObject newDog = Instantiate(dogObject, vector3, quaternion, transform);

            DogController newDogController = newDog.GetComponent<DogController>();
            newDogController.iDogID = dogType;
        }

The code instantiates the dog object at the requested position and parents it to an object, then attempts to connect to the DogController script (which is connected to the prefab in the assets folder), however in runtime this component does not exist and therefore doesn’t work.


I’m really quite stuck with this. I’ve used virtually the same code on a previous project and it worked, but this time it doesn’t work. Additionally, it doesn’t look like a lapse in save data as I never saved the prefab without a reference to the Dog Controller instance. It’s also puzzling because the Event Trigger script is still available in runtime, however, loses its references.

If anyone can tell me if this is unusual behaviour or if this is expected and I’m doing something wrong that would be much appreciated :slight_smile:

For anyone wondering, I just deleted and re-created the prefab and everything seems to be functioning fine.

This was almost definitely a bug that seems to be surrounding the saving of prefabs, but I’m not sure how to recreate it to file a bug report so I’ll just let it sit for now.

and it is… i hope… i have the same behaviuor. i added a component to a gameobject in a prefab, my component doesn’t hinerits from monobehaviour direcly, but whith in a subclass. when i instanciate the prefab within unity 2021.3 the component doesn’t show. now i still have to figured out if i destroy somewhere or is a unity bug or somenthing. i don;t yet. but thanks for your sharing.