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 GunslingerBara · Oct 04, 2012 at 05:08 PM · gameobjecteditorposition

Forcing all new GameObjects to a specific Position z-value

Hello everyone! When dragging/dropping a prefab or GameObject to the scene, it tends to have a random z-value. I was wondering if it was possible to force every prefab, GameObject, etc. that is dragged from the Project view to the Heirarchy or Scene to have a specific z-value for Position. Is this possible?

FYI, this is for a 2D game, where the z-value determines where an object is in front of or behind other objects (so having a consistent "starting point" goes a long way).

Comment
Add comment · Show 1
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 GunslingerBara · Oct 16, 2012 at 08:28 PM 0
Share

Yes, I mean while working in the editor. Doing it to the rigidbody unfortunately will not work for me. Any tips on what I should be trying to do in an editor script to get this to work?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Oct 16, 2012 at 06:40 PM

Well if its a rigid body I think you can possibly set the z axis in the prefab to zero. and then in the prefab lock Z axis. That might force all prefabs dragged to keep the prefabs Z axis of zero (or whatever number)

the constraints are under rigidbody. I myself dont know of anyway to put constraints on just a transform. At least not in the editor, could you script one up easy but it'd only go into affect once you began the game.

Comment
Add comment · Show 7 · 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 sparkzbarca · Oct 16, 2012 at 06:43 PM 0
Share

I checked that and nope it doesnt work, it only works if you drag it into the hierarchy not the scene.

avatar image GunslingerBara · Oct 16, 2012 at 06:46 PM 0
Share

Unfortunately the objects in question are not rigid bodies. Is there any way to set the z-axis using Editor Scripts?

avatar image DDelapena · Oct 16, 2012 at 08:38 PM 0
Share

var zPos : float = 0.0;

function Update() { gameObject.transform.position.z = zPos; }

that way you have control in the component. I imagine it would force it in the value set in the zPos... but i don't think this is ideal.. there should be a way to lock $$anonymous$$ and max values in Z in edtiro preferences or something.. when dropping prefabs in scene.. =\

avatar image GunslingerBara · Oct 16, 2012 at 08:51 PM 0
Share

Is there a concept in Unity of editor scripts that are always running in the background? If so, I can write an editor script that watches events on the Project tab and whenever something is dragged and dropped I can change it's z-index. Is that possible?

avatar image DDelapena · Oct 16, 2012 at 09:10 PM 0
Share

I've got an idea...

http://docs.unity3d.com/Documentation/ScriptReference/DragAndDrop-objectReferences.html

get object name being dragged and dropped and then..

http://docs.unity3d.com/Documentation/ScriptReference/ScriptableObject.OnEnable.html

refer to that script getting the object and applying a certain value to the z axis, of that object.

Show more comments
avatar image
0

Answer by WarmBiscuit · May 25, 2017 at 02:52 PM

The objects that you're dragging from the Prefab and placing into the scene are going to have a Z-Value relative to the original Z-Value of the Prefab. In order to get everything on the same Z-Value plane, you need to make sure to "Reset" the position of the Prefab before dragging items into the scene from it.

All the items will have different Z-Values (as well as X and Y values) depending on what the coordinate values of the original Prefab are. So make sure to reset your Prefabs to the origin before dragging objects from it into your scene.

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

12 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

Related Questions

Change default sprite position when dragged into Hierarchy 1 Answer

in-editor cloning of game objects 1 Answer

I want to move a cube with rotation but I find this problem 1 Answer

Get the name of an instance's prefab at runtime? 0 Answers

Physics.OverlapSphere() not working after using pool of objects 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