언리얼 C++ vs Blueprint OnRep_ Function

정재훈·2025년 7월 4일
0

unreal engine

목록 보기
44/45

In Unreal Engine Blueprints, the OnRep (or RepNotify) function for a replicated variable is automatically called on both the server and the client when the variable changes, regardless of whether the change originates on the server or a client. This is different from C++, where the OnRep function is only called on clients when a replicated variable changes on the server.

Explanation:
Replication in Unreal Engine:
When a replicated variable changes on the server, it's automatically replicated to all connected clients.

OnRep Functions:
OnRep functions are designed to be called whenever a replicated variable's value changes, allowing you to update related game state or visuals on the receiving end.

Blueprint vs. C++:
In Blueprints, the OnRep function for a replicated variable is automatically called on both the server and clients when the variable changes, regardless of where the change originated. In C++, the OnRep function is only called on clients when a replicated variable is changed on the server.

Why the difference?
The blueprint system handles the calling of the OnRep function on the server when a variable is changed in the blueprint, while in C++, it's the developer's responsibility to call the OnRep function manually on the server when replicating the variable.

Example:

  1. Define a replicated variable:
    In your Blueprint, create a variable (e.g., MyReplicatedVariable) and set its replication to Replicated and Replicates Using with an OnRep function (e.g., OnRep_MyReplicatedVariable).

  2. Implement the OnRep function:
    In the Blueprint, create a function named OnRep_MyReplicatedVariable and add your desired logic (e.g., updating a UI element, changing a material).

  3. Change the variable:
    When you change MyReplicatedVariable on the server or a client, the OnRep_MyReplicatedVariable function will be automatically executed on both the server and that specific client.
    In essence, the OnRep function in Blueprints offers a convenient way to synchronize state across all instances (server and clients) when a replicated variable is modified.






참조 사이트
1. Why repnotify’s functions is got called on Server as well ?
2. Differences with RepNotify in C++ and Blueprint

profile
드가자

0개의 댓글