The difference between Monobehaviour and Node class - Realm Rush

Hey Everyone, I had a hard time getting my head around why we are using Node in Ream Rush, As we delve deepr in to the course I undarstood It was not possabile to idle on that feeling.
So I asked for chatGPT to explain it to me and he did such a great job I wanted to share it with anyone that might encounter the same poblem:

Node as a Non-Monobehaviour Class: The Node class specifically manages information about each square on your game grid. It stores details like coordinates, walkability, exploration status, etc.
MonoBehaviours for Game Logic: MonoBehaviours in Unity handle game-related behaviors, like player movement, enemy AI, interactions, etc. They’re scripts attached to game objects and are responsible for the game’s functionality.

# The Map and Stickers Analogy:

1. Map Represents Your Game Grid:

  • Imagine you have a big map on a wall representing your game grid. Each square on this map is a location in your game where characters can move.

2. Stickers Represent Node Information:

  • Each square on the map needs some details written on it, such as whether it’s walkable, explored, part of a path, etc.
  • Instead of directly writing these details on the map (which might make it messy), you use small stickers containing this information.

3. Node Class as a Sheet of Stickers:

  • Now, think of the Node class as a special sheet of stickers specifically designed to hold information about each square.
  • This sheet of stickers ( Node class) has spaces to write down details like coordinates, walkability, exploration status, etc., for each square on your map.

4. MonoBehaviours as Actions and Behaviors:

  • In your game world, you have characters and objects moving around this map.
  • MonoBehaviours are like sets of instructions or actions given to these characters and objects. For instance, how a character moves, how an enemy behaves, etc.
  • These instructions (MonoBehaviours) are attached to the characters or game objects, guiding their actions in the game.

5. Separation for Organization and Clarity:

  • If you directly wrote details on the map, it might become cluttered and confusing. So, you use stickers (Nodes) to keep it clean and organized.
  • Similarly, in programming, separating the Node class from MonoBehaviours helps keep the game logic (like moving characters, enemy behaviors) separate from the data and details of the game grid (Node information).

Benefits of Separation:

  • Clarity and Organization: Just as stickers neatly organize information on the map, separating the Node class organizes and manages information about each square.
  • Clean Code Structure: Keeping MonoBehaviours focused on behaviors and actions, while the Node class manages grid-related data, helps maintain a cleaner and more understandable code structure.
  • Modularity and Reusability: It allows you to reuse the Node logic for different parts of your game without mixing it up with specific behaviors tied to game objects.

This separation creates a clear structure, making it easier to manage and develop different aspects of your game independently.

Privacy & Terms