Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
1
Question by mukilol · Jul 02, 2016 at 02:42 AM · positioncoordinatesonmouseup

Instantiate creates object at wrong position

Hey!

I got the following code:

 using UnityEngine;
 using System.Collections;
 
 public class PlaceTower : MonoBehaviour {
 
     public GameObject towerPrefab;
     private GameObject tower;
 
     void OnMouseUp () {
         if (canPlaceTower ()) {
             tower = (GameObject) 
                 Instantiate(towerPrefab, transform.position, Quaternion.identity);
         }
     }
 
     private bool canPlaceTower(){
         return tower == null;
     }
 }
 

which is supposed to spawn a tower once you click on the white cube on the terrain: https://gyazo.com/aceb98fd0a1d79b62bcba6e48a7db4b6

Tower position: https://gyazo.com/23528d0b2a3ed889100eebc9dc10d3d9

The tower should be placed on the exact same position as the cube which it apparently is since the spawned tower has the same coordinates as the white cube but the tower is located somewhere else upp in the air.

Does someone know what the issue could be?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Frostblood · Apr 06, 2018 at 06:12 PM

I had the same problem and found out my prefab transform had a default position in it's transform which was causing the offset. You would think a prefab would always be at exactly where you spawn them but they actually add their transform position to the position you give them when instantiating. (To fix it just change the prefab transform position to 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
0

Answer by ronny3050 · Jul 02, 2016 at 05:13 PM

The issue is your OpenSpot is located at y = 0 which is in the air, relative to your ground which has some negative y value. I suggest dragging the OpenSpot down until it hits the ground and then try spawning again.

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
0

Answer by yonoodle · Nov 12, 2016 at 08:37 AM

I just run into similar problem with wrong instantiate position , might not be the same issue as yours ,

I checked all hierachy are set to (0,0,0) and also all the animation begin with (0,0,0)

that solved my problem , which caused by editing the animation at non origin(0,0,0) position and the animator saved the displacement value

besure you click "apply change to Prefab" from "GameObject" menu after changing all position to 0,0,0

good luck!

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
0

Answer by shyxiaolong · Mar 15, 2021 at 09:06 AM

in my case i was initialise coordinates before use base class of instance. and and this led to different coordinates.maybe someone find here solve problem

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

63 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

Related Questions

Getting position of a coordinate on the surface of a sphere 0 Answers

Converting mouse(touch) position with ScreenToWorldPoint doesn't work. 1 Answer

Cell size to Canvas size 1 Answer

How to move object after set it to certain position? [VR Rift] 0 Answers

How to make my Player smaller if he moves the y coordinate up? 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