Controller(1)

1. What is Controller?

        As the name suggests, Controller is the controller. It is a proxy object for the player in the game and a bridge for interaction between the player and the characters or AI in the game. Its task is to control all behaviors of the character or AI. It can be said that the Controller plays with the characters and AI in the palm of his hand.

        Controller is derived from Actor, so of course it has the basic attribute Tansform of Actor, which gives Controller the ability to exist in the game level; it has the serialization function, which is implemented in the root class UObject; it has the network copy function, which gives it In online games, you can network copy to the server.

        In the game level, the Controller is usually not visible. What? Since it is an Actor, why is it not visible in the game level? We looked at the source code of the Controller.cpp file and found that SetHidden(true) is initialized by default in the constructor as shown below:

Maybe you will ask, if this is the case, why should it be invisible by default?              

Hmm~ o(* ̄▽ ̄*)o This is a good question...

                ​​​​​​​        ​​​​​​​        ​​​​​​​        ​​​​​​​        

        The Actor itself does not have any shape or color, and the Actor white ball icon can only be seen in the editor mode. No shapes or colors are visible in game mode. Its function is an intermediary. We only care about its function and not its appearance. (There are older singles in the program, so I couldn’t sit still. Well, my requirements are not high. I don’t care about appearance, as long as I can play.) Then I went to the bathroom and came back with numbness in my legs and feet).

        ​​​​​​​        ​​​​​​​        ​​​​​​​        ​​​​​​​                

        All in all, it's of no use even if you see it, so just hide it.

2. Life cycle

        Since a Controller can exist in a Level, does it mean that the Controller is a member of the Level and its life cycle begins and ends with the Level? The answer is no, the Controller exists in Level but does not belong to Level.

        In the article UE's world view, it has been mentioned that the World is composed of multiple Levels. This shows that the Controller does not care whether Level exists. It belongs to World, and its identity is equivalent to Level.

        Therefore, the existence of Controller is not necessarily related to Level. It is an outsider that exists across Levels and will intervene in the logic within Level and between Levels from time to time.

3. Why is it designed this way and what role does it play in the UE core framework?

        Epic's original idea when designing Unreal Engine was based on the MVC (Model-View-Controller) architectural pattern. The Controller separates the data layer Model and the presentation View to implement separated logical processing, which is in line with the single-function principle of the design pattern. This allows developers to be more organized when reading the engine source code, and makes the original design intentions of the engine architect easy to understand.

        Controller is one of the most important classes in the core framework of the unreal engine source code. It is the player's agent in the game and is responsible for transmitting the player's operations to the game character or AI (for example, the player operates the keyboard to move or attack), and is also responsible for transferring the character's actions to the game character or AI. and AI information and status feedback to the player (for example, when a game character is injured, the game controller will vibrate).

4. Properties of the Controller class.

        

Guess you like

Origin blog.csdn.net/zhang1461376499/article/details/118112450