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 itzik009s · Nov 29, 2012 at 01:15 PM · mousestatictargetsingleton

SetCursorPos reset when reloading scene

hello i am using

 DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
     
 public static extern int SetCursorPos(int x,int y);

to take control of the mouse by using an eyetracker....Everything works fine.....but...after i die in the game, or reload the scene..... the static setcursorpos doesn`t reinitialize....i tried singleton or other suggested approaches in the unity answers....but it still doesn`t work? Do you have any other sugestions how to solve the problem? I am working on a windows powered tablet....that has mouse input...Instead of mouse can i use Raycast in order to determine if my eyetracker coordinates are over a gameobject`s collider?

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 PAEvenson · Nov 29, 2012 at 01:16 PM 0
Share

When you made it a singleton did you use DontDestroyOnLoad? http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html

avatar image itzik009s · Nov 29, 2012 at 01:25 PM 0
Share

yes...can you maybe elaborate a little bit on a method how to do it properly? I `ve tried lots of methods for the last past weeks, and none of those is working properly.....The thing is that i get x and y screen coordinates from the eyetracker, which i then replace this coordinates in an update function in SetCursorPos(gazex,gazey).....working really good..undless i restart the scene..when it stops working....I am using it to check if the mouse is over an enemy, and then renders a HUD target over it, and changes it`s tag to enemy, so the rocket seeker....shots it....Would there be a better method to have this on hover effect without using and taking control of the mouse? Your help is highly apreciated

maybe something like this:

http://forum.unity3d.com/threads/64880-Troubles-with-raycasting-to-find-tags

where the point of shooting the ray is a Vector2 that holds the eyetracker x, y coordinates

1 Reply

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

Answer by PAEvenson · Nov 29, 2012 at 01:36 PM

Here try something like this:

 using UnityEngine;
 using System.Collections;
 
 public class MouseManager : MonoBehaviour
 {
     private static MouseManager m_Instance = null;
     
     public static MouseManager Instance
     {
         get 
         {
             if(m_Instance == null)
             {
                 m_Instance = (GameObject.Instantiate(Resources.Load("Prefabs/MouseManager"))as GameObject).GetComponent<MouseManager>();
             }
             
             return m_Instance;
         }
     }
     
     void Awake()
     {
         GameObject.DontDestroyOnLoad (gameObject);
     }
     
     //place your code here
     
     //
     
 }


You will need to make a prefab and place it in your resources folder and attach the script to it. DO NOT add the prefab to the scene. It will load itself when you try to access it. I havent tested the code..there maybe a bug or 2, but should be a good start for you.

I've had issues in the past when I reloaded a scene with a plugin that used a dll. I dont think it was cleaning up properly and didnt release the windows handle. Hope this helps

Comment
Add comment · Show 8 · 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 PAEvenson · Nov 29, 2012 at 01:44 PM 1
Share

".....working really good..undless i restart the scene..when it stops working...." I think the issue is with the dll and windows handle, not your eyetracking...

avatar image itzik009s · Nov 29, 2012 at 02:04 PM 0
Share

Thank you...$$anonymous$$y script was attached to the camera...so you suggest i create an empty prefab, that i don`t use in the scene? cause my eyetracking code was in the same script as well...so i want to make sure it works

avatar image PAEvenson · Nov 29, 2012 at 02:09 PM 0
Share

The only thing that needs to be in the prefab is the DLL import stuff. I would then change all my SetCursorPos calls to use $$anonymous$$ouse$$anonymous$$anager.Instance.SetCursorPos(). That way all you need to do is a "Find" in $$anonymous$$onoDevelop for SetCursorPos and replace it with $$anonymous$$ouse$$anonymous$$anager.Instance.SetCursorPos or whatever you call it.

avatar image PAEvenson · Nov 29, 2012 at 02:13 PM 1
Share

Yea, if you had the DLL import stuff on your $$anonymous$$ainCamera, when the scene reloaded you probably had 2 mainCamera in the scene now. Then, the DLL Import got recalled again breaking the windows handler.

avatar image PAEvenson · Nov 29, 2012 at 03:35 PM 1
Share

wait what exactly doesnt work? When you restart the scene is it still broken? Or does it not work on the tablet?

Show more comments

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

11 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

Related Questions

Attack/Targeting Script Issue 1 Answer

Throw with mouse 1 Answer

Variable Accessors in UnityScript (Get{} and Set{}) 1 Answer

Static target in the srcipt for my Prefab 2 Answers

Singleton instance accessed in coroutine always null 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