Skip to main content
added 207 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28

You can simply pass the top object to the children and call a function directly on it. This guarantees that you don't have to rely on parent propagation. So you don't end up doing silly things like transform.parent.parent

You could however automate this process with GetComponentInParent. This retrieves the first script it finds. Then cache that in your collision object, directly call functions on said cached object.

This will retrieve the first occurring script that it finds.

Alternatively you could make use of UnityEvents ( don't use Messages ) to bind functions to the child object. With unity events you can add any arbitrary listener so you can do more than just notify the top level object of the child object being hit.

You can simply pass the top object to the children and call a function directly on it. This guarantees that you don't have to rely on parent propagation. So you don't end up doing silly things like transform.parent.parent

You could however automate this process with GetComponentInParent. This retrieves the first script it finds. Then cache that in your collision object, directly call functions on said cached object.

This will retrieve the first occurring script that it finds.

Alternatively you could make use of UnityEvents ( don't use Messages ) to bind functions to the child object. With unity events you can add any arbitrary listener so you can do more than just notify the top level object of the child object being hit.

You can simply pass the top object to the children and call a function directly on it. This guarantees that you don't have to rely on parent propagation. So you don't end up doing silly things like transform.parent.parent

You could however automate this process with GetComponentInParent. This retrieves the first script it finds. Then cache that in your collision object, directly call functions on said cached object.

Alternatively you could make use of UnityEvents ( don't use Messages ) to bind functions to the child object. With unity events you can add any arbitrary listener so you can do more than just notify the top level object of the child object being hit.

added 207 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28

You can simply pass the top object to the children and call a function directly on it. This guarantees that you don't have to rely on parent propagation. So you don't end up doing silly things like transform.parent.parent.parent

You could however automate this process by looping trough each parent to check if a certain object containswith GetComponentInParent. This retrieves the first script that receives the call andit finds. Then cache that in your collision object. Then simply, directly call functions on said cached object.

This will retrieve the first occurring script that it finds.

Alternatively you could make use of UnityEventsUnityEvents ( don't use Messages ) to bind functions to the child object. With unity events you can add any arbitrary listener so you can do more than just notify the top level object of the child object being hit.

You can simply pass the top object to the children and call a function directly on it. This guarantees that you don't have to rely on parent propagation. So you don't end up doing silly things like transform.parent.parent.parent

You could however automate this process by looping trough each parent to check if a certain object contains the script that receives the call and cache that in your collision object. Then simply directly call functions on said cached object.

Alternatively you could make use of UnityEvents ( don't use Messages ) to bind functions to the child object. With unity events you can add any arbitrary listener so you can do more than just notify the top level object of the child object being hit.

You can simply pass the top object to the children and call a function directly on it. This guarantees that you don't have to rely on parent propagation. So you don't end up doing silly things like transform.parent.parent

You could however automate this process with GetComponentInParent. This retrieves the first script it finds. Then cache that in your collision object, directly call functions on said cached object.

This will retrieve the first occurring script that it finds.

Alternatively you could make use of UnityEvents ( don't use Messages ) to bind functions to the child object. With unity events you can add any arbitrary listener so you can do more than just notify the top level object of the child object being hit.

Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28

You can simply pass the top object to the children and call a function directly on it. This guarantees that you don't have to rely on parent propagation. So you don't end up doing silly things like transform.parent.parent.parent

You could however automate this process by looping trough each parent to check if a certain object contains the script that receives the call and cache that in your collision object. Then simply directly call functions on said cached object.

Alternatively you could make use of UnityEvents ( don't use Messages ) to bind functions to the child object. With unity events you can add any arbitrary listener so you can do more than just notify the top level object of the child object being hit.