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 CornDog · Oct 14, 2013 at 09:24 PM · errorinstantiateprefab

Setting the parent of a transform which resides in a prefab error

I'm getting the following error:

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

ON the following bit of code:

 public void GenerateSectors() {
         
         ClearLocations();
         GameObject locationPrefab = GameObject.CreatePrimitive(PrimitiveType.Cube);
         locationPrefab.AddComponent("Location");
         
         for (int i = 0; i < numberOfLocations; i++) {
             Vector3 rand = Random.insideUnitSphere * 90f;
             rand.y = 0.0f;
             
             
             GameObject newLocation = (GameObject)Instantiate(locationPrefab, rand, Quaternion.identity);
             
             newLocation.transform.parent = mapParent.transform;
             locations.Add(newLocation.transform);
             
         }
         
         Destroy(locationPrefab);
     }

I have searched the internet and the forums for an answer as to why this is happening. AND I have found several people who encountered a similar problem. I believe I Have made the needed changes to my code so it would work (according to information found through searching.) but alas, I have been unsuccessful.

I'm trying to create a bunch of cubes, set their parent to a predefined object, and add them to a list so I can manipulate and destroy them later.

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 robertbu · Oct 15, 2013 at 12:54 AM 1
Share

I know what usually generates this error, and I don't see it in this script. I hacked your code a bit to get it to compile and run, and I had no problems (compile time or run time):

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Bug25c : $$anonymous$$onoBehaviour {
     
 void Start() {
     GenerateSectors ();    
     }
     
 List<Transform> locations = new List<Transform>();
     
  public void GenerateSectors() {
  
        //ClearLocations();
        GameObject locationPrefab = GameObject.CreatePrimitive(PrimitiveType.Cube);
        locationPrefab.AddComponent("Rigidbody");
  
        for (int i = 0; i < 100; i++) {
          Vector3 rand = Random.insideUnitSphere * 5.0f;
          // rand.y = 0.0f;
  
          GameObject newLocation = (GameObject)Instantiate(locationPrefab, rand, Quaternion.identity);
  
          newLocation.transform.parent = transform;
          locations.Add(newLocation.transform);
  
        }
  
        Destroy(locationPrefab);
     }
 
 }

Once in a rare while I have a issue where Unity does not recompile a script that I have modified. I suggest closing Unity, make a modification to the script and save it, and reopen Unity.

avatar image CornDog · Oct 15, 2013 at 02:58 AM 0
Share

Thanks for the attempt. I tried restarting as you suggested. But still getting the error.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Amineeee · Jun 12, 2017 at 08:45 AM

facing the same problem , am pretty damn sure there is nothing wrong with the code , for instance i am instantiating two objects in a scene with the same way , one is working fine and assigned to the right parent the other is not and getting this error

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

15 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

Related Questions

Instantiated gameObject(here, wall) destroyed, but when checked for existence, shows that it exists, how? 1 Answer

Instantiate Not Working - Boo Script 1 Answer

Enemy not spawning correctly 1 Answer

updateMassFromShapes error 2 Answers

Start() of Instantiated Prefabs Not Being Carried Out? 1 Answer


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