• 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
Question by lamp · Jun 02, 2014 at 12:55 PM · movementcoroutineupdatesmooth

[ANSWERED]Move object without Update or coroutine

Ok so i am aware there are a number of ways to smooth move an object from point A to point B either through the Update() or using a coroutine. But as for discovering a way to do t$$anonymous$$s without either of these is proving to be somewhat problematic. I came across t$$anonymous$$s but could not get it working at all. Usually I would use a coroutine but in t$$anonymous$$s case my specifications state otherwise. Does anyone out there have a solution or a link to a script reference I can investigate?

Comment

People who like this

0 Show 5
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 Nerevar · Jun 02, 2014 at 01:02 PM 1
Share

well you have this function

I don't know what kind of specifications you have but not using update() or coroutines to move your objects is weird.

avatar image robertbu · Jun 02, 2014 at 01:22 PM 1
Share

Understanding the problem you are trying to solve might help us direct you to an answer. I agree with @Nerevar that what you are trying to do is strange on the surface. You need to cause something to execute regularly:

  • FixedUpdate()

  • LateUpdate()

  • On the Repaint type in OnGUI() (not recommended)

  • InvokeRepeating() (as suggested by @Nerevar)

  • Chained Invoke (not recommended)

avatar image lamp · Jun 02, 2014 at 02:39 PM 0
Share

When the user swipes a direction, a GameObject moves to a specific location depending on the direction of the swipe, which i want it to move there over time. To my understanding as it waits on user input to be called I cant use update. I have been instructed by the project lead to avoid using Coroutines which is how I would usually execute something like this.

I will try the Invoke Repeating Method that Nerevar suggested. I would not get away with using an animation as there are 4 different animations from each original position and 9 original positions. To many animation files.

The reason im instructed to avoid coroutines is that i am told they can be unreliable with large projects and can cause more issues than they solve. Do you know of evidence to support this? in my own work i use them fairly often with few problems?

avatar image lamp · Jun 03, 2014 at 08:14 AM 0
Share

Ok yeah I get you. Had a bit of a brain fart. I used a enum state Machine and checked it within the update for movement and got it sorted now. Just as a side point, I assume that using an enum or state machine to constantly check within the update would be more costly than Coroutines? From what I can see there doesn't seem to be many drawbacks to coroutines

oo and thanks for the helps

avatar image Andres-Fernandez · Jun 03, 2014 at 08:49 AM 2
Share

Update functions are events, events that are always triggered if they exist in the script (check the docs on execution order). Even if your Update function is empty, it will always execute every frame (generating some unnecesary overhead, very small overhead, but overhead after all). Coroutines controlled by yield instructions can also be executed every frame, same as updates. The good thing about coroutines, is that once they finish, they won't bother anymore (unlike the Update function that will stay there forever, even if it doesn't do anyting anymore).

Of course, there are some variations, like FixedUpdate function that executes whenever you want, and yield WaitForSeconds that allows you to manage its execution.

I'm not saying that you shouldn't use Update to check your state machine and perform the movement (actually that's not a bad idea after all), because that is not a too heavy of an operation. What you shoud try to avoid is using heavy operations like GameObject.Find() in your Update. Just remember that Update triggers every frame, so be gentle with it.

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Andres-Fernandez · Jun 02, 2014 at 03:59 PM

There's no reason you can't use Update. You just need some flag to trigger the movement (and the flag being set by the swipe made by the user). Inside your update you can check the flag, if it's true, then move. The end of the movement sets it back to false.

It's a problem of the logic used to trigger the movement, not the method used to move the object.

Comment
Loius

People who like this

1 Show 0 · 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

Answer by Andres-Fernandez · Jun 02, 2014 at 01:32 PM

What about an animation? If you know point A and point B you can just create it procedurally by code.

[EDIT] I've done it before, all you need to check is AnimationClip , SetCurve and AnimationCurve in the docs.

Comment
Loius
EarthHobbit

People who like this

2 Show 0 · 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

22 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

Related Questions

using coroutines for move objects - performance. 1 Answer

smooth movement through waypoints 1 Answer

Jumping in my FPS causes the player to teleport instead of smoothly jumping, and gravity doesn't work as it's supposed to 1 Answer

Smooth Camera Movement script with problem. 0 Answers

[WORKAROUND] How to time pause in update (yield) 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