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 rimawi · Jan 23, 2011 at 01:46 AM · prefabparenting

Parenting a prefab

Hi,

I am trying to make a game like Frogger. When you jump on the log you move with log.

So I created a Prefab that's randomly being called and it move down the river.

My issue when I jump on the log, I get an error message saying :

Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption. UnityEngine.Transform:set_parent(Transform)

Here is the code to Instantiate the prefab:

var prefab:Transform; var Platform:Transform;

function appear () {

var position = Vector3(Random.Range(74.4, 76.2), 2, Random.Range(-8,-7));

var Platform= Instantiate(prefab,position, Quaternion.identity);


Here is the Parenting Code it is on the Player, The prefab is tagged as Platform :

var myplatformSides:GameObject;

function OnControllerColliderHit(hit: ControllerColliderHit) {

if(hit.gameObject.tag=="Platform"){

transform.parent=myplatformSides.transform; }

else

transform.parent=null; }

Thank you

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
2
Best Answer

Answer by Bunny83 · Jan 23, 2011 at 02:07 AM

My guess is that you bind a prefab to "myplatformSides" and you use this prefab reference like a GameObject instance. I think you want to do something like:

function OnControllerColliderHit(hit: ControllerColliderHit) {
    if(hit.gameObject.tag == "Platform"){
        transform.parent = hit.gameObject.transform;
    }
    else
        transform.parent = null;
}

or can you explain for what you use the "myplatformSides" variable? Is it set to an instance of your prefab?

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 rimawi · Jan 23, 2011 at 02:18 AM 0
Share

You are right I did bind it.

And your correction Works Perfectly.

Thank You

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

No one has followed this question yet.

Related Questions

How to parent a prefab? 2 Answers

Parenting an instantiated Prefab... again 1 Answer

How to make an Instantiated prefab a Child of a gameobject that already exists in the hierarchy 3 Answers

GameObject parenting during runtime 1 Answer

Problems with nested prefabs 4 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