Is it Bad Practice to Raise Event in Update?

I’m trying to figure out if I’m raising an event too often. I have a Player class which calls a raycast during its Update(), and raises an event if the ray collides with anything:

Player()
{
   void Update()
   {
     RaycastHit   hit;

     // Raise event if player detects anything.
     if (Physics.Raycast(m_Transform.position, m_Transform.forward, out hit, m_MaxRayDistance))
     {
        OnPlayerDetect(hit.collider, hit.distance);
     }
   }
}

Part of me thinks that this is not the best use for events. I’m afraid that this might be inefficient and have potential to slow down the game if there are too many subscribers.

Is this a good use of the event? If not, what’s an example of a more efficient way?

This is a rather broad question because events are a very versatile and relatively basic feature. Generally though: Compared to its use and potential alternatives events are very performant, so no, it’s not bad practice. In fact, I would be more concerned about raycasting every frame (depending on how many instances run this script.) Either way, premature optimizations are bad practice as well: Unless you notice a slow-down in your specific use-case, considering performance of small bits of code in Unity projects does generally more harm than good (obviously expensive/slow operations such as writing to disk excluded.)

it depends on whether or not the raycast needs to be constant or if it needs to be more event oriented.

example: if your raycast is based on where the player is looking then using it in update should be fine since the player can be looking all over every frame

but if your ray cast is more event oriented then using it update is a bit much
example: if you have to click to “examine” what the player is looking at
or if a player has to use a “skill” like in an rpg