• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by IsaacShea · Jan 26, 2020 at 05:36 AM · instantiateprefabcomponents

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): alt text

And below is my prefab upon creation during runtime: alt text


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 :)

screen-shot-2020-01-26-at-31204-pm.png (89.8 kB)
screen-shot-2020-01-26-at-31219-pm.png (80.2 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HAndLol · Jan 26, 2020 at 03:09 PM 0
Share

did you double check everything? because this is very odd

avatar image IsaacShea HAndLol · Jan 27, 2020 at 06:18 AM 0
Share

I have. $$anonymous$$y only thoughts are that it could be an issue with that one instance of unity being open, or i should delete and re-create the prefab.

It is really bizarre

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by IsaacShea · Jan 27, 2020 at 06:22 AM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image IsaacShea · Jan 29, 2020 at 12:25 AM 0
Share

I've been working on the project overall and I found out what was wrong with it. There was a line in the code that was responsible for deleting the dog if it was an "overflow" (which the ones created using code were mistakenly classed as), but ins$$anonymous$$d of having Destroy(this.gameObject) I missed .gameObject, which caused it to "delete" itself but leave the object, causing weird behaviour.

This is not a bug on Unity's end as it turns out, it's just me forgetting pieces of my code.

avatar image medinaline IsaacShea · Jan 29, 2020 at 02:47 AM 1
Share

I'm glad you found it. I spent some time with this over the weekend trying to figure out what the issue could be. Thanks for updating the post. It may be helpful to someone in the future.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

170 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiated prefab loses components 1 Answer

prefab is instantiating without a script 2 Answers

Lobbing a Bomb with Instantiate. 1 Answer

Randomly pick then create prefab 2 Answers

Prefabs dont instantiate directly on point 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges