0

Example: there are objects A and B. Object A must connect with object B (by Script) and object B must connect with object A (by Script). How to do it more properly:

  1. Create Scripts for each objects.
  2. Create Empty Object and add one Script to it, and then in this Script to create two references (for A and B)?
3
  • Can you be more explicitly? do you mean communication between objects/classes? Commented Oct 21, 2022 at 17:12
  • Yes, I mean exactly this! I need to call some Methods and get some info Commented Oct 21, 2022 at 17:22
  • You shouln't call any other objects methods most of the time! if you do, your code base going to be a spaghetti. Commented Oct 21, 2022 at 17:37

1 Answer 1

0

What you describe at section 2 is known as Mediator pattern. You should definitely use it or you can also use Observer pattern. The difference between them is there's a mediator between them which causes loosely coupling.

The common part between them is whenever an event happens to the object itself, it throws a callback and the other objects gets notified and do their own jobs.

To even make a better organization you can look at MVC(S) and ECS architectural pattern.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.