Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 WackyTatum · Jul 11, 2015 at 05:04 PM · transformprefabparentinstance

Setting parent causes prefab error

The full error is:

Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption

I have googled and most of the instances of others facing this issue seem to be related to them directly accessing a prefab. However, as you can see in the code below, I am instantiating an prefab and directly accessing a gameObject in the scene. Anyone got any ideas?

  public void UpdateMesh(GameObject newMesh, GameObject skinnedRoot)
 {
     GameObject newBody = GameObject.Instantiate(newMesh);
     GameObject oldBody = gameObject.transform.GetChild(0).gameObject;

     newBody.transform.parent = oldBody.transform.parent; //Setting parent error
     newBody.transform.position = oldBody.transform.position;
     newBody.transform.rotation = oldBody.transform.rotation;
     newBody.transform.localScale = oldBody.transform.localScale;

     GameObject.Destroy(oldBody); //Destroying asset not permitted error
     _bodyMesh = skinnedRoot;
     _animator = newBody.GetComponent<Animator>();
     _animationObject = newBody;
 }
Comment
Add comment · Show 4
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 BobBobson108 · Jul 28, 2015 at 08:50 PM 0
Share

I'm getting the exact same error for the same reason. $$anonymous$$y code below:

  Transform modelGO = Instantiate(Resources.Load(dbEntry.path, typeof(Transform))) as Transform;
  Debug.Log("instantiated model");
 
  modelGO.parent = thisTransform;
avatar image Jessespike · Jul 28, 2015 at 09:00 PM 0
Share

Have you tried Transform.SetParent()?

avatar image BobBobson108 · Jul 28, 2015 at 09:12 PM 0
Share

Just tried that and I am getting the same error. Are you not able to repo this? I'm running Unity 5.1.1f1.

I'm wondering if it has something to do with loading from Resources in my case.

avatar image BobBobson108 · Jul 28, 2015 at 09:25 PM 0
Share

Found my problem! I was calling the Init() function (which I posted the code from above) on the prefab.

 $$anonymous$$yClass myClass = Resources.Load(myClassPath, typeof($$anonymous$$yClass)) as $$anonymous$$yClass;
 Debug.Log("Instantiating...");
 
 Instantiate($$anonymous$$yClass);
                 
 $$anonymous$$yClass.Init(dbEntry);

0 Replies

· Add your reply
  • Sort: 

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

22 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

Related Questions

setting the parent of a transform which resdes in a prefab is dusabled to prevent data corruption 1 Answer

Enemy only chasing pre-fab's original location, not instance's 2 Answers

Accessing children of instances vs children of original prefab 1 Answer

Howto set main.camera as a parent when main.camera itself is a child of a prefab 1 Answer

Instantiate a Prefab as child 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