UE4Server study notes

Run on Server

Recently, when I was learning the operation of UE4's local area network connection, and then learned RPC, I thought of a question. If I write a Run On Server event in the AI ​​​​class, and then this event is triggered on the client, will it be passed to the server.

test

First look at the player class:
insert image description here
insert image description here
the main idea is to press F to execute an IINTRACE event, which is set to No Replicated. Then shoot a ray, if the ray touches the enemy (Enemy_SwardBP) class, call its Test event.
Enemy class:
Test event:
insert image description here
The main function is to generate a simple square ACTOR. The Test event is set as the Run on server event.
After running, the logic of the ray is executed on the client side. It means that the player on the client side shoots a ray, then hits the enemy, and makes the enemy call the Run On Server event.
The results are as follows:
insert image description here
the client is on the right. According to the printed results, the ray hits the enemy, but the Test event is not invoked. Through the test with a breakpoint, it is found that the Test event does not run at all. It can be seen that if you want AI to directly call the Run on server event on the client, it will not be transmitted to the server at all, and the client will not execute the corresponding logic.
If the player's IINETRACE is changed to Run on server, the result is as follows:
insert image description here
the normal operation is generated.

in conclusion

Ai cannot directly run the Run on server event, and it will not run locally. If you want AI to realize the operation of notifying the server to execute the event, you need to use the player class. Only the playercontroller can pass messages from the client to the server to perform operations.
You can refer to the following figure:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_44840850/article/details/125184378