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 /
  • Help Room /
avatar image
1
Question by Deadcow_ · Jan 06, 2016 at 08:12 PM · mousedragslidereventsystemevent triggering

Disable current drag of UI.Slider

I've got UI'Slider, that constantly slides to Slider.value = 0, if not dragged. So, you drag slider to the end and if you release mouse at some point - slider will run to the initial position. If you hold slider at value = 1 for a few seconds - something happend, and slider should be released automatically and go to the initial point.

To check if dragged I use EventTrigger with BeginDrag and EndDrag;

If not dragged = lerp slider value to the zero;

If dragged and value is 1 = start to count;

If counter filled = disable drag + some event;

And now I'm stumbled into this problem - how to disable drag? I want slider to act like PointerClick or PointerUp is raised, even if user still holds mouse button. (and user must click again to drag the slider).

I tried to set slider.interactable = false for one frame, or set EventSystem.current.SetSelectedGameObject(null);. No luck.

How to reset EventSystem.pointerDrag, or any other tricks to resolve this?

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 Spatanz · Jun 01, 2016 at 05:36 PM 0
Share

I facing this issue too, anyone has solution?

avatar image Deadcow_ Spatanz · Jun 01, 2016 at 06:51 PM 0
Share

I posted my solution for this. Hope it's helped

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Deadcow_ · Jun 01, 2016 at 06:51 PM

The only solution I had found is this:

 var input = EventSystem.current.GetComponent<StandaloneInputModule>();
 input.DeactivateModule();

This code is called when I need to release my slider while it's dragging by mouse.

AFAIK this BaseInputModule.DeactivateModule() forces main input module to reinitialize its values, like current dragged object. I tested this out, this call seemed to be safe to use

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 Spatanz · Jun 02, 2016 at 04:35 PM 0
Share

Wow, work like a charm, thanks man.

avatar image
0

Answer by bibbis · Jun 23, 2018 at 10:47 AM

Hello,

Perhaps someone else will find their way here.

Another option is to add an "EventTrigger" component to the slider in the inspector.

Add a new event of type "PointerUp", and then you can assign functions to it.

If you simply want to reset the slider itself to 0 or another specific value on release, you just drag the slider into the empty Object and select Slider > float value, and then enter the value.

If you need something more complex, you can instead drag a GameObject that has your script on it and assign the function to YourScript > YourFunction.

Perhaps you want YourFunction to do more than just reset the slider, and you don't want to add tons of functions to the Pointer Up event.

Just be careful when assigning references through the inspector like this. It can become very messy if you link several different objects through inspector references.

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

42 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

Related Questions

Event on mouse up 2 Answers

onClick Event for UI Text? 1 Answer

UI stopped working 0 Answers

Issue with dragging 2D objects diagonally 0 Answers

How to Event tigger when drag and drop complete 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