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 AC_reaper · Nov 03, 2014 at 10:31 PM · rigidbodyprefabprefabsclonerigidbodies

Prefab clone not working

Hi everyone,

Im very new to unity and I am trying to create 5 of the same game object using a prefab but for some reason it does not work. (http://docs.unity3d.com/Manual/InstantiatingPrefabs.html iv been using this)

I have done all of the instructions (create cube, add rigidbody and drag it into the prefab) and the code in the script is as followed

 using UnityEngine;
 using System.Collections;
 
 public class multiboxes : MonoBehaviour {
 
     public Rigidbody boxR;
 
     // Use this for initialization
     void Start () 
     {
         for (int i = 0; i < 5; i++) 
         {
             Vector3 position = new Vector3 (Random.Range (-3.0f, 3.0f), Random.Range (-2.0f, 2.0f), -2.0f);
             Rigidbody boxclone = (Rigidbody)Instantiate (boxR, position, Quaternion.identity);
         }
     }
 
     // Update is called once per frame
     void Update () 
     {
     
 
     }
 }

I have also made sure that I dragged the prefab into the BoxR rigidbody.

alt text

Any help will be very appreciated.

prefab data.png (179.0 kB)
Comment
Add comment · Show 3
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 AC_reaper · Nov 03, 2014 at 10:08 PM 0
Share

the problem I am having is that the cubes are not appearing on the screen

avatar image AC_reaper · Nov 03, 2014 at 10:43 PM 0
Share

the camera is at 0,0-10 (is faceing the correct direction) and as you can see from the screen shot, gravity is off and there is a Rigidbody (it was on the component when I dragged it over) you have any other ideas this is really wierd?

avatar image JSierraAKAMC · Nov 03, 2014 at 10:52 PM 0
Share

I think the reason they are not being created is because you are instantiating RigidBodies. You should be instantiating GameObjects. I'll get back with you in a few $$anonymous$$utes with working code.

1 Reply

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

Answer by JSierraAKAMC · Nov 03, 2014 at 11:01 PM

Here, try this code: using UnityEngine; using System.Collections;

 public class multiboxes : MonoBehaviour {
 
     public GameObject boxR;
     
     // Use this for initialization
     void Start () 
     {
         for (int i = 0; i < 5; i++) 
         {
             Vector3 position = new Vector3 (Random.Range (-3.0f, 3.0f), Random.Range (-2.0f, 2.0f), -2.0f);
             GameObject boxclone = (GameObject)Instantiate (boxR, position, Quaternion.identity);
         }
     }
     
     // Update is called once per frame
     void Update () 
     {
         
         
     }
 }
 

The reason it wasn't working is that you were trying to instantiate Rigidbodies, which are just components. To actually create an object, you would have to instantiate a GameObject. I hope this helps.

Comment
Add comment · Show 3 · 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 JSierraAKAMC · Nov 03, 2014 at 11:03 PM 0
Share

Oh, and make sure to attach this script to the camera, not the cube itself.

avatar image AC_reaper · Nov 03, 2014 at 11:15 PM 0
Share

o that works ty :)

avatar image AC_reaper · Nov 04, 2014 at 04:46 PM 0
Share

can I just ask if you dont $$anonymous$$d why it seemed to work for robertbu and not me ?

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

2 People are following this question.

avatar image avatar image

Related Questions

Cant delete clones of prefab 1 Answer

Rigidbodies violently repel when replacing with pre-shattered opject 2 Answers

i attach the prefab, but when i hit play, its not the prefab anymore 0 Answers

Instantiated prefab doesn't collide with player 0 Answers

Array of prefabs 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