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 ferraribeng · Jul 14, 2011 at 08:04 AM · performancepluginlagdll

Data is lagging the external device. Why?

I am trying using a 3D input device. I have the C/C++ DDL file in the plugin folder. I was able to read the data from the input device using the DLL API.

I am now experiencing this problem. When I move the device, the data I read and displayed using Debug.Log, lagged by about 1 second. This is not good because whatever I want to animate in Unity cannot respond to me instantanteously. I have no idea what causes the lag.

I wrote another program in C++ to read the data through the same DLL and display it. Interestingly, there is no lagging at all. Seem like the problem is interaction between Unity and the DLL.

I have been looking through the forum for anyone with similar problem, but don't seem to find any. Any advice and pointer will be deeply appreciated. Thanks.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ferraribeng · Jul 27, 2011 at 03:19 AM

Hi,

I have finally determined what the problem is and fixes it. Here is a write up of what the problem is and how I resolve it.

Cause of problem:
I have a read device data API function inside my DLL to read the device data once. I called this function from Unity C# script each time I want to read the device data. The data read is stored in variables. The variables can then be assessed by calling another DLL API function to get the varaible data. Naturally inside the C# script Update function, I called the read data API function to initiate a read device data and then I call the API function to get the stored device data from the variables. The update function effectively allows an endless loop reading of the device data.

It is apparent that each time I call the DLL API read device data function, there is a 1 second delay in execution of the function due to interface between Unity and DLL read function. This subsequently result in delay in updating the variables. Therefore, when I call the DLL API function to read the variables immeidately after the call the read device data functon, I am really reading the old data. Therefore, this caused a lagging respond.
.

Solution to the problem:
I have to change the C++ DLL coding a bit.

I created a thread inside the DLL to read the device data and store the data in private variables in a While loop. Therefore, the DLL will continuously reading the device data in the background. This ensure that variables containing the device data is constantly being updated.

At Unity C# script, I just call the API function to get the device data from the variable. In this way, I do not have any lagging respond at all as oppose to having to initiate a read device data.

This is my solution. It is very much like the mouse under windows, C# script or JavaScript is only reading the current data from a variable, rather than tell the mouse to read.

  • hope this info is helpful to someone outthere. Have fun...*

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

2 People are following this question.

avatar image avatar image

Related Questions

How do I get maximum performance on extremely heavy calculations? 1 Answer

Can I use my own input device? 4 Answers

Access Multiple Camera Streams 0 Answers

Load a DLL only when needed ? 1 Answer

How to link to scripts in the Package Manager when building a dll. 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