• 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
2
Question by ManiacalSquare · Apr 02, 2012 at 02:37 PM · prefabinstance

Changing the instance, not the Prefab.

I'm instancing a prefab in my game. However when I change the rigidbody.drag using a script that's on the prefab/instance,
it changes the drag permanently for all instances that come after that as well (basically it just changes the prefab itself).
I just want it to change it for that perticular instance.

How would I go about doing that?

Thanks in advance.

Comment
Add comment · Show 10
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 Bunny83 · Apr 02, 2012 at 02:39 PM 0
Share

That doesn't make much sense. Can you post your code? I guess you don't use the reference that is returned by Instantiate, right?

avatar image ManiacalSquare · Apr 02, 2012 at 02:51 PM 0
Share

maybe this will help:

I have a prefab called "nmydropper". It has another prefab "chutist" as a child. In my scene I'm instantiating nmydropper. However when I look at the instances, it seems that only the parents (nmydropper) become clones, and the child prefab (chutist) does not. Not sure why this is.

avatar image Bunny83 · Apr 02, 2012 at 03:04 PM 0
Share

child prefabs? There are no child prefabs in Unity. A prefab can contain a GameObject hierarchy but there are no child prefabs.

Again, post the code of your script and how you instantiate the prefab.

avatar image ManiacalSquare · Apr 02, 2012 at 03:32 PM 0
Share

var chutistInstance : GameObject; static var drop : boolean = false;

function Start () {

 Instantiate(chutistInstance, Vector3(transform.position.x,transform.position.y -0.85, transform.position.z),transform.rotation); 

}

function OnTriggerEnter(Col : Collider){

if (Col.gameObject.tag == "Bullet"){

  life -= 10;

}

if (life == 0){

  chutistInstance.rigidbody.drag = 0;
  drop = true;
  yield WaitForSeconds (0.01);
  destruct();

}

avatar image Eric5h5 · Apr 02, 2012 at 04:04 PM 1
Share

The docs for Instantiate explain it more than adequately, with code examples.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Apr 02, 2012 at 04:39 PM

 var chutistPrefab : GameObject;   // this is the prefab reference set in the inspector
 var chutistInstance : GameObject; // this is the reference to the instance created in start
 
 function Start () {
     chutistInstance = Instantiate(chutistPrefab, Vector3(transform.position.x,transform.position.y -0.85, transform.position.z),transform.rotation);
 }

But as Eric said the docs explain everything very detailed:

http://unity3d.com/support/documentation/Manual/Instantiating%20Prefabs.html
http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html

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 ManiacalSquare · Apr 02, 2012 at 06:37 PM 0
Share

I finally figured out why it wasn't working for me. Feel pretty stupid XD But that's part of the fun I guess ;)

Thanks for your replies guys!

avatar image
0

Answer by ManiacalSquare · Apr 02, 2012 at 05:50 PM

 var chutistInstance : GameObject;
 static var drop : boolean = false;

 function Start () {
 
     Instantiate(chutistInstance, Vector3(transform.position.x,transform.position.y -0.85, transform.position.z),transform.rotation); 
 
 }


 function OnTriggerEnter(Col : Collider){
  
  if (Col.gameObject.tag == "Bullet"){
      
      life -= 10;
  }
  
  if (life == 0){
      
      chutist.rigidbody.drag = 0;
      drop = true;
      yield WaitForSeconds (0.01);
      destruct();
  }
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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Updating variable on another script. It is not working. 2 Answers

Enemy health. Need to take damage from two different bullet prefabs 1 Answer

is there a way to make a script prefab? 1 Answer

Tagging object while instating not working. 3 Answers

Understanding prefab updating its instances 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