Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 hdhiman · Mar 12, 2017 at 05:44 PM · updatetranslatestart

calling transform.Translate outside of Start() or Update()

Hi there, I'm working on a 3d model that needs parts to be set to a 'disassembled' position in the beginning, that is, away from their original position. The parts are then made visible as the user goes along and completes the assembly steps. Each step is represented by a state, and at the end of each state, the corresponding parts are back in their 'assembled/original' position. This script attaches to all such objects:

 public class Behaviour : MonoBehaviour {
 
     public float x_diff = 0;
     public float y_diff = 0;
     public float z_diff = 0;
 
     // Starting/Ending points
     private Vector3 move;
 
     private void Awake()
     {
         move = new Vector3(x_diff, y_diff, z_diff);
     }
 
     public void Start()
     {
         // THIS WORKS
         transform.Translate(move);
     }
 
     public void show()
     {
         gameObject.SetActive(true);
     }
 
     public void hide()
     {
         gameObject.SetActive(false);
     }
 
     public void move_out()
     {
         // THIS DOESN'T
         transform.Translate(move);
     }
 
     public void move_back()
     {
         transform.Translate(-1 * move);
     }
 
 }

Each state calls these functions as needed. Here's the problem:

  • the function move_out() is not reliably moving the objects. Some move, others don't.

  • when this happens, move_back() ends up placing objects further away in the other direction.

Calling move_out() in Start() is an option but it only runs once, so the state is not able to 're-initialize' the objects back. Do I need to figure out a way to call move_out() and move_back() in Update() ? Any suggestions?

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 hdhiman · Mar 09, 2017 at 10:22 AM 0
Share

Some more observations:

  • The objects move eventually, just that some of these objects (and they're always the same objects) don't move on the first call. If I call move_out() twice, some objects are displaced twice the distance, others only once.

  • I've also found that I can use OnEnable() and OnDisable() to trigger the same behaviour, will give this a try.

I guess the last resort will be to have two copies of each part, one in the 'disassembled' position and the other in 'assembled' position. Seems simpler, but not as elegant. I would prefer finding a good solution ;)

avatar image hdhiman · Mar 13, 2017 at 08:59 AM 0
Share

Tried OnEnable() and OnDisable() - no change in behaviour.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hdhiman · Mar 13, 2017 at 04:25 PM

Finally figured out how to get this to work. Just save the position during Start() and use it to reset elements back to their 'original' position when needed.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Use my own update() and start() methods. 1 Answer

Why if I execute .SetText on the Start it dont works. 1 Answer

GetComponent in the Update function? 1 Answer

Choppy movment for even the most basic stuff 2 Answers

Start being called after Update of another GameObject? 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