Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 DejaSenti · Jun 23, 2021 at 10:59 PM · raycastunity 2dphysics2draycastingphysics2d.raycast

Is it possible to raycast during edit mode?

So I have this custom made navmesh editor for 2D pathfinding used by enemies in the game. I can add nodes, connect them, disconnect them, move them around, whatever, and then assign them to an enemy for ingame use.

What I'm trying to do is make an option to automatically fill a space with nodes and connect them in a grid-like manner, BUT not connect them when a platform is in the way. For this purpose, each potential connection between two nodes is checked via raycast on my "World" layer which contains all the platforms. If there's a collider found, no connection is made and the algorithm moves on to the next connection. If there's no collider, the algorithm makes a connection and moves on.

The thing is, raycasting doesn't work in edit mode at all.

Expectation: alt text Result:alt text

When I hit Play and test the very same code, raycasting returns everything as needed, and gives the expected result.

It is worth mentioning that the editor script inherits from Editor (which, in turn, inherits from ScriptableObject), and the raycasting is performed under certain conditions during OnInspectorGUI. ExecuteInEditMode, ExecuteAlways, etc. didn't work, nor did a separate MonoBehaviour, as raycasting apparently only updates in the next FixedUpdate, which (to my knowledge) can't be forced like regular Update.

I could make the mesh in Play mode and then copy the results, but it's far from ideal.

Any suggestions?

(This is Unity 2019.4.18f1)

photo-2021-06-23-18-18-01.jpg (29.2 kB)
photo-2021-06-23-18-17-57.jpg (29.1 kB)
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
0

Answer by Boolean_of_True_th · Jun 24, 2021 at 12:16 AM

Ive never tried this but if you need your script to run in edit mode this might be relevant. Hope this helps.

https://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html

Comment
Add comment · Show 5 · 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 DejaSenti · Jun 24, 2021 at 12:51 PM 0
Share

Unfortunately it didn't, nor did the other options e.g. ExecuteAlways. The thing is that the script which executes the raycast is inheriting from Editor and not MonoBehaviour, and the raycast is executed under certain conditions within OnInspectorGUI().

avatar image spilat12 DejaSenti · Jun 26, 2021 at 07:09 PM 1
Share

I think you should mention this in the original question, these details would affect responses.

avatar image Boolean_of_True_th · Jun 24, 2021 at 04:44 PM 0
Share

I guess I'm probably out of my league on this one then... I have no idea how Editor scripts work, sorry.

avatar image Boolean_of_True_th · Jun 24, 2021 at 05:00 PM 0
Share

maybe you could use a MonoBehavior that continually updates in editor mode to call your function within your Editor script, might be a terrible solution. the cone below forces itself to constantly update, i don't know but maybe you could use it to call logic from your editor script.

 using System.Collections;
 using UnityEngine;
 
 [ExecuteAlways]
 public class Script : MonoBehaviour
 {
     // Start is called before the first frame update
     void Start()
     {
     }
 
     // Update is called once per frame
     void OnDrawGizmos()
     {
         if (!Application.isPlaying)
         {
             UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
             UnityEditor.SceneView.RepaintAll();
         }
         GameObject.Find("sp").transform.Rotate(0, 0, 10);
     }
 }

i found this code on another forum https://forum.unity.com/threads/solved-how-to-force-update-in-edit-mode.561436/

avatar image DejaSenti Boolean_of_True_th · Jun 26, 2021 at 10:05 PM 0
Share

I tried and unfortunately it didn't work, because apparently raycasting yields a result after FixedUpdate, which cannot be forced during Edit.

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

179 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can RaycastHit2D.point be inside a BoxCollider2D if raycast was performed from outside that collider? 1 Answer

Raycasting not behaving as expected? 2 Answers

script problem even though i have no errors 2 Answers

How to get co-ordinates of end point of Raycast2D ? 1 Answer

Physics2D Raycast not detecting wall colliders 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