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 Posly · Feb 13, 2012 at 09:32 PM · prefabfpsconnectionprefab connection

Can I stop the prefab connection of a gameobject during play?

Ok I'm making a FPS and I'm trying to make a script that will allow the player to pick up weapons off the floor. I do this by instantiating the weapon in front of the player and parenting the weapon to the player. Every thing work's fine but when I made the weapon a prefab it didn't work and an error message came up and it said something like "parenting a prefab is disabled to prevent data corruption". So my solution is to break the connection of the prefab in the awake function? But I don't know how to stop the prefab connection. Anything will help thanks!

 var weaponHoldPoint : Transform;
 var pistol : Transform;
 var assualt : Transform;
 
 function Start ()
 {
     Instantiate(pistol, weaponHoldPoint.position, transform.rotation);
     pistol.transform.parent = transform;
 }
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 Anxo · Feb 13, 2012 at 10:13 PM 0
Share

this should not be necessary. You can totally instantiate a prefab and bechild it to another object. I would look to fix the roof of the problem ins$$anonymous$$d of hot fixing it.

Lets see a screen shot of your setup or show some code. I am wondering if you are instantiating a child of a prefab ins$$anonymous$$d of the full prefab.

avatar image Bunny83 · Feb 13, 2012 at 10:22 PM 0
Share

This error usually come up when you try something like that at edit mode or when you try to parent the actual prefab to something (not an instance). At runtime there is no prefab connection... Prefavs are an Editor feature.

At runtime there are only two types of objects:

  • scene objects (that are all objects in the current scene)

  • off scene objects (that are objects that are loaded, but aren't visible since they aren't in the scene. That objects used to be prefabs in the editor. You can use them as cloning source and instantiate a clone into the scene, but the object itself can't be parented to something since it doesn't belong to the scene)

I suggest you just add the script snippet you're using to your question (just edit your question).

$$anonymous$$y guess is you either try to do something at edit-time, or you work with the prefab reference directly ins$$anonymous$$d of the cloned object.

avatar image Posly · Feb 13, 2012 at 10:29 PM 0
Share

Should I add "pistol.transform.parent = transform" part into the awake function of the pistol?

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · Feb 13, 2012 at 10:32 PM

Like i thought you are not using the clone. You try to parent the prefab directly!

Instantiate() returns the cloned object. prefab is just the source object. You should do it like this:

var weaponHoldPoint : Transform; var pistol : Transform; var assualt : Transform;

function Start () { var clone : Transform = Instantiate(pistol, weaponHoldPoint.position, transform.rotation); clone.parent = transform; }

You should take a look into the manual for Instantiate

Comment
Add comment · Show 1 · 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 Posly · Feb 13, 2012 at 10:35 PM 0
Share

Ohhh I get it! Thanks a bunch! Work's like a charm!

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

7 People are following this question.

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

Related Questions

PrefabUtility.ReplacePrefab overrides changes 0 Answers

Prefab connection problem 1 Answer

Patterns for reusing, inheriting from, or extending GameObjects or Prefabs. 0 Answers

[Urgent] Bring back a prefab that was accidently changed? 1 Answer

Cloned Prefab 3 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