• 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
0
Question by Digital-Phantom · Mar 29, 2015 at 12:40 PM · raycastsceneresourcesnumbersmaximum

How many raycast can be running in a scene without it being considered too many?(Solved)

Simple scene... player object, a few obstacles and an enemy using raycast to detect/attack the player - All good.

Next scene... player object, a few obstacles and maybe as many as 52 enemies all using the same raycast method to detect/attack the player.

Is t$$anonymous$$s going to be over-taxing on my game/resources

???

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
3
Best Answer

Answer by fafase · Mar 29, 2015 at 12:52 PM

Should not since Raycast is just multiplication and division of a few values.

The real question is do you need casting each frame? Could you maybe make them less frequent like only 4 times per second (already a cast each 25ms w$$anonymous$$ch sounds enough).

 private float freq = 0.25f; // 4Hz
 void Update(){
    timer +=time.deltaTime;
    if(timer> freq){
        timer = 0;
        AIMethod();
    }
 }
Comment
Add comment · Show 4 · 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 Digital-Phantom · Mar 29, 2015 at 01:23 PM 0
Share

Was already thinking something the same. I was going to try a do it using random range, but your suggestion looks more efficient.

I'll give it a go implementing your script.

Thanks

:)

avatar image TokyoWarfareProject · Aug 27, 2018 at 04:25 PM 0
Share

Would InvokeRepeating be an alternative?

avatar image fafase TokyoWarfareProject · Aug 29, 2018 at 08:48 AM 0
Share

Yes it could be.

avatar image Owen-Reynolds · Aug 27, 2018 at 04:57 PM 0
Share

Well, depending on the scene, a raycast could be hundreds of lines. For example, if it's checking for the same layer as those 52 enemies and passes by lots of them, and they use Mesh colliders (it checks the bounding box first, but if it passes close by, it has to check the mesh, too).

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 Raycast2D over Tilemap? 0 Answers

When object (sphere) come to specific position, change scene (C#) 0 Answers

Add object using other scene,Change something in scene from the menu 2 Answers

GUI label apears on it self,I have a GUI lable. The text apears on it self. 0 Answers

Making a Deckbuilder 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