• 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 Miicck · Sep 02, 2017 at 02:52 PM · instantiatetransformprefabparentprefab-instance

Setting parent of instantiated object fails (Error: setting parent of prefab is disabled...)

I have an object that I instantiate and I immediately attempt to set it as a child of something, which fails with the error "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption". The pattern is something I've written many times before, and I understand what the error is saying, but I don't see how this is possible given the object has been instantiated and so shouldn't be a prefab. Here is the code:

  var myRecipe = Instantiate(Resources.Load<recipe>("Recipes/woodenWall"));
  myRecipe.transform.SetParent(transform);

The second line is the one that fails; unity takes me right there in the stack trace.

I can see the instantiated object in the hierarchy, and it is definitely the same object as the one stored in the variable "myRecipe", I just can't set it's parent (note: I can change to and get the same error). Has anyone ran into this problem before?

Thanks.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Miicck · Sep 02, 2017 at 02:57 PM

Ah, I found out what was going wrong: It wasn't the myRecipe.transform object that was having issues, it was the transform I was trying to set it as a child of. Apparently the error "Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption" in this case means "Setting the child of a transform which resides in a prefab is disabled to prevent data corruption".

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

106 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

Related Questions

Parenting GameObjects 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

parenting instantiated object 2 Answers

Getting instance of an sub object rather than the original's subobject 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges