• 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 jtok4j · Oct 22, 2017 at 07:50 PM · instantiateprefablocation

Instantiate a prefab results in a new prefab in a different location than expected

Pulling my hair out, trying to use Instantiate for the first time ever... I can instantiate a copy of a prefab, but using the script below causes the prefab to be instantiated at the exact location of the "original" in scene. What I'm trying to do, is instantiate at the original start location of the original in-scene prefab. Where am I going wrong? I store the location of the original prefab at the start, but it doesn't seem to instantiate at that original location... ?

Script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class makenewcoin : MonoBehaviour {
     public GameObject coinstartlocation ;
     public Vector3 newcointransformstartlocation;
     private Vector3 cointransform; 
     private Quaternion coinrotate; 
     private bool coinalreadycreated = false; 
     // Use t$$anonymous$$s for initialization
 
 
     void Start(){
          
         Debug.Log ("location of coinstartlocation is:" + coinstartlocation.transform.position);
         cointransform = coinstartlocation.transform.position; 
         coinrotate = coinstartlocation.transform.rotation;
     }
 
     void OnTriggerEnter(){
 
         if (!coinalreadycreated) {
             
             Instantiate (coinstartlocation, cointransform, coinrotate);
             Debug.Log ("made a new coin at the location of gameobject: coin at" + cointransform);
             coinalreadycreated = true;
         }
 
     }    
         void OnTriggerExit(){
             coinalreadycreated = false; 
         }

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by SteveDizzle · Oct 22, 2017 at 09:02 PM

 private Vector3 cointransform; 

by default would be (0, 0, 0)

you could make it public

 public Vector3 cointransform; 

then enter the position you want to use in the editor

or you can try using

 Instantiate (coinstartlocation, transform.position, coinrotate);


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 Bonfire-Boy · Oct 24, 2017 at 08:22 AM 0
Share

Since they set the value of cointransform in Start(), it's not clear to me why the default value is relevant.

avatar image
0

Answer by WainWork · Oct 24, 2017 at 08:11 AM

Are u shure that problem not on parent transforms? Maybe u settings prefab location w$$anonymous$$le he was a c$$anonymous$$ld somet$$anonymous$$ng?

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

105 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 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 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 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 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 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 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

Instantiating prefab of object like it was in the scene 0 Answers

Instantiate a random prefab at an objects location 3 Answers

How to instantly move a newly instantiated prefab? 2 Answers

Instantiating prefab with certain coordinates problem (c#) 0 Answers

Instantiate New Gun 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