Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by n1gth · Jul 02, 2015 at 12:18 AM · instantiateprefab

Any reason why script vanishes from prefab when instantiated?

I have a Player prefab. It has a few scripts on it - but one of them, when added to a prefab, is not there when the prefab instantiates. Only that script disappears, the rest are fine.

To work round, I call AddComponent() in OnStartServer, and all is then fine, but I'm just wondering what would cause a script to vanish from a prefab at instantiation time with no errors...

Comment
Add comment · Show 3
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 meat5000 ♦ · Jul 01, 2015 at 08:05 PM 0
Share

You probably Destroy it.

If you drag the prefab to scene, does it still exist there?

avatar image n1gth · Jul 02, 2015 at 11:32 AM 0
Share

Yes it's there when I drag it over. But I'm not doing anything special with the components on that script after instantiation.

avatar image n1gth · Jul 02, 2015 at 11:46 AM 0
Share

I've had another look, I can't see anything odd about it.

I put a debug statement into the Awake function for the vanishing script. Only time it gets called is when the manual AddComponent happens.

2 Replies

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

Answer by Ibzy · Jul 02, 2015 at 12:00 PM

Are you able to provide your Start() and Awake() functions of the offending script, and maybe a view of the inspector of the prefab?

With you using OnStartServer I imagine this is with UNET? Do you have the same prefab in the list of spawnable objects in your NetworkManager? I had a similar problem and found that it was set to a different prefab with a very similar name.

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 n1gth · Jul 02, 2015 at 01:16 PM 0
Share

Ah ha. Thank you Ibzy for that.

I had a look at the Lobby$$anonymous$$anager. It had the "Game Player Prefab" set. However, the Spawn Info section didn't have anything set, and furthermore the Spawnable Prefabs didn't have the player set there.

I don't think they are actually needed, correct me if I'm wrong, but it seems like NetworkLobby$$anonymous$$anager for some reason uses its own m_GamePlayerPrefab field rather than using the Network$$anonymous$$anager.m_PlayerPrefab. But anyway, just to try, I added my Player prefab to both the Spawn Info section and the spawnable prefabs - and now - it worked - the script was there at instantiation.

However, then I took the prefabs out again (ie my Player Prefab was only set in "Game Player Prefab"), in order to narrow down exactly what fixed it. But it kept working... so it looks like something went weird with the Network$$anonymous$$anager prefab set up in the editor, and it corrected itself.

avatar image Ibzy · Jul 02, 2015 at 01:22 PM 0
Share

I think the Network$$anonymous$$anager stores a cache in the editor, and you will likely find the game crashes when you try to run it in standalone if you haven't set the spawnable prefab.

I spent about 4 days rolling back all sorts of changes to rectify the problem I had (the crashing) to eventually find this little dickens.

Glad it's sorted.

avatar image
0

Answer by n1gth · Jul 02, 2015 at 08:40 PM

Looked like a issue with the editor, see my comment above. By tweaking the NetworkLobbyManager in the Inspector it resolved itself.

If I manage to reproduce I'll raise a bug report. It's now all working OK, even when I add extra scripts.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to Add Y Axis Offset to transform.localPosition on an Instantiated Prefab? 2 Answers

Referencing gameObject from script after Instantiate 0 Answers

Instantiating one prefab with different materials in one frame 0 Answers

Prefab of a whole scene? 3 Answers

how to destroy camera instatiated from prefab? 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