• 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
1
Question by fireDude67 · Jun 21, 2011 at 12:49 AM · raycastoptimization

Memory Requirement of a RayCast

I am going to develop a game in which the AI preforms several RayCasts at the same time. Will this slow down my game, or will it be okay?

Comment
Add comment · 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 save · Jun 21, 2011 at 01:01 AM 0
Share

Approximately how many AIs will cast how many rays and how often do they have to do it? Doing it in an Update without some sort of control will impact performance at some point of (low) quantity.

It also depends greatly on what you do with the information that returns along with a ray.

avatar image fireDude67 · Jun 21, 2011 at 01:44 AM 0
Share

Approximately 10-50 AI's will do it. They will only do it once. No one seems to want to answer my questions these days :(

avatar image ckfinite · Jun 21, 2011 at 02:28 AM 0
Share

I have raycast a 10X10 grid at once (don't ask), and I got reasonable slowdowns. You should be fine.

avatar image Chris D · Jun 21, 2011 at 02:29 AM 0
Share

The answer (probably) is: it depends. What are you developing for, mobile or PC? If you're only doing it once, it'll probably only slow things down once (if at all). Have you considered different approaches to the problem you're trying to solve? What data do you need from each raycast?

avatar image fireDude67 · Jun 21, 2011 at 04:14 AM 0
Share

PC. All I need is the name of the object the raycast collided with.

1 Reply

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

Answer by aldonaletto · Jun 21, 2011 at 02:51 AM

I tested 256 blocks casting 10 rays each per frame; raycasting could be enabled or disabled. With raycasting disabled, deltaTime was around 15.7 mS. When enabled, it rose to 21.8 mS. Since there were 2560 raycasts by frame, the time taken by each one was about 2.38 uS.
This benchmark run in my notebook (1.8GHz Intel Core Duo, not the fastest machine in the world), and in the Editor. Maybe in Standalone mode it run faster, but I don't think the difference will be too significant.
Anyway, it would be necessary about 400 raycasts to increase the frame time by 1mS, so I think you will not have too much problem with your 50 raycasts in any PC.

Comment
Add comment · Show 3 · 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 Joshua · Jun 21, 2011 at 03:06 AM 0
Share

note that on mobile devices the slowdown will be significantly higher.

avatar image aldonaletto · Jun 21, 2011 at 03:55 AM 0
Share

Yes, the time taken by raycast should vary a lot across different machines - specially different graded CPUs. The raycast probably is done mainly in software by the CPU (with exception of NVidia PhysX and other GPU powered physics engines). $$anonymous$$obile devices are way slower than any PC, and certainly don't have any hardware to help them to calculate physics.

avatar image fireDude67 · Jun 21, 2011 at 04:15 AM 0
Share

Soo I think I shouldn't have problems with 400 R/C slowing down 1millisecond..

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dynamic Occlusion Culling 1 Answer

Understanding Raycast How Actually works in Unity [As Algorithm] 2 Answers

Code optimisation techniques? 1 Answer

Optimize 2D menu game by disabled raycast target 1 Answer

Raycast Delay 3 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