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 Damonic217 · Apr 13, 2015 at 10:51 PM · c#gameobjectinstantiateprefab3d models

Spawning a prefab at another object's location

Hi there, I'm doing a project that involves a cube breaking up into smaller pieces, i'm doing this by deleting the cube and replacing it with a prefab made of smaller cubes to give it that breaking effect.The problem i'm having is that the prefab is spawning at the wrong location and i'm not sure where to change it.

Here is the code i'm using , its done in C#

 using UnityEngine;
 using System.Collections;
 
 public class BlockDestory : MonoBehaviour 
 {
     public GameObject remains;
     void Update () 
     {
         if (Input.GetKey (KeyCode.Space))
         {
             Instantiate(remains,transform.position,transform.rotation);
             Destroy(gameObject);
         }
     }
 }

I've also added some pics of the inspector incase you need them. alt textalt text

Thanks /D

3.jpg (208.6 kB)
1.jpg (201.8 kB)
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 lordlycastle · Apr 14, 2015 at 03:55 AM 0
Share

Please format your code.

avatar image Damonic217 · Apr 14, 2015 at 12:12 PM 0
Share

The code has been edited, thanks for the link. It has some very good tips for future questions.

3 Replies

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

Answer by Scorpox · Apr 13, 2015 at 11:09 PM

I see that your Fragments prefab is a group. Is the pivot of this group centered on the object? If not, drag the prefab to the scene, then select it and click on GameObject in the upper menu. There you'll se an option that says "Center on children". Click on that option and apply the changes to the prefab. You can now delete it from the scene.

I don't say this is the solution, but it could be one solution. ;D

Regards

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 Damonic217 · Apr 14, 2015 at 12:52 PM 1
Share

This worked for me, thank you :)

avatar image
1

Answer by glennhk · Apr 14, 2015 at 02:23 AM

Be sure that the prefabs are always positioned at (0,0,0).

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
avatar image
1

Answer by lordlycastle · Apr 14, 2015 at 03:59 AM

The problem is that every smaller cube in the group is not positioned at centre of the group. When you click the child you can see in the inspector that it’s position is not (0,0,0) (The second pic). Change that to zero then it should spawn in correct poison. Also I see that have rigid body on the cubes so you’ll have to destroy the big cube first then spawn the smaller ones. To do that simply cache the poison to a local variable and destroy, then spawn.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

gameObject are not referenced 2 Answers

How to associate underlying data structure to prefab at runtime? 1 Answer

How do I make prefab follow a gameobject?(C#) 1 Answer

Trouble with destroying an instantiated prefab 2 Answers

Save gameobjects prefabs from scene A to a list, then instantiate those game objects to another scene. 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