ue4 RepNotify ReplicatedUsing 区别
2016-04-27 12:58
3571 查看
在ue4种,在服务器修改了某个变量,想触发回调,有两种方式,一个是在蓝图中,一个是在C++中,但这两种用法是有区别的
在蓝图中,变量标记为RepNotify,假设响应函数为OnRep_Fun1,则当变量改变时,OnRep_Fun1会在服务器和所有客户端调用,ue4文档原文如下:
https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/Networking/ReplicateVariable/Blueprints/index.html
(This is called whenever the variable we assigned as RepNotify changes and will be executed on both the server and client machines)
在C++中,想要达到这种效果,需要用ReplicatedUsing 标记,用法如下:
UPROPERTY(Transient, ReplicatedUsing=OnRep_TeamColor)
int32 TeamNumber;
但注意,在C++中,只有客户端的OnRep_TeamColor函数会被调用,服务器要想调用,需自己手动进行,参考如下:
https://forums.unrealengine.com/archive/index.php/t-3709.html
04-27-2014, 06:37 AM
One key difference between how blueprints and C++ handle the "rep notify" concept is that in blueprints any time a RepNotify variable is set, the OnRep function is automatically called on the server (and on the client when the update happens). In C++, the server
does *NOT* automatically get the ReplicatedUsing function called, only the client does when it gets its update. If you want the server to call that function, you have to do so manually. I've had a decent number of requests to show porting the last 2 parts
of the blueprint networking tutorial to C++, so I'm hoping I can do that some day soon when I find some time.
Also, whenever you are changing health, you'll want to make sure you're only doing so on the server. If you aren't already, the C++ equivalent of the blueprint macro node for checking authority is:
if (Role == ROLE_Authority)
由于以上原因,尤其是在进程既是服务器又是客户端时,需要自己去调用相关的处理,因为此进程的OnRep_TeamColor不会被调用
在蓝图中,变量标记为RepNotify,假设响应函数为OnRep_Fun1,则当变量改变时,OnRep_Fun1会在服务器和所有客户端调用,ue4文档原文如下:
https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/Networking/ReplicateVariable/Blueprints/index.html
(This is called whenever the variable we assigned as RepNotify changes and will be executed on both the server and client machines)
在C++中,想要达到这种效果,需要用ReplicatedUsing 标记,用法如下:
UPROPERTY(Transient, ReplicatedUsing=OnRep_TeamColor)
int32 TeamNumber;
但注意,在C++中,只有客户端的OnRep_TeamColor函数会被调用,服务器要想调用,需自己手动进行,参考如下:
https://forums.unrealengine.com/archive/index.php/t-3709.html
04-27-2014, 06:37 AM
One key difference between how blueprints and C++ handle the "rep notify" concept is that in blueprints any time a RepNotify variable is set, the OnRep function is automatically called on the server (and on the client when the update happens). In C++, the server
does *NOT* automatically get the ReplicatedUsing function called, only the client does when it gets its update. If you want the server to call that function, you have to do so manually. I've had a decent number of requests to show porting the last 2 parts
of the blueprint networking tutorial to C++, so I'm hoping I can do that some day soon when I find some time.
Also, whenever you are changing health, you'll want to make sure you're only doing so on the server. If you aren't already, the C++ equivalent of the blueprint macro node for checking authority is:
if (Role == ROLE_Authority)
由于以上原因,尤其是在进程既是服务器又是客户端时,需要自己去调用相关的处理,因为此进程的OnRep_TeamColor不会被调用
相关文章推荐
- 初始化UIView的两种方式
- Java源码解析-BlockingQueue
- 设置UIButton中的文字和图片,设置UILabel的文在显示不同颜色
- 设置UIButton中的文字和图片,设置UILabel的文在显示不同颜色
- GradleUserGuide中文版 10)网页应用 11)Gradle命令行
- Map集合中value()方法与keySet()、entrySet()区别
- Question1
- IOS键盘的相关设置(UITextfield)
- mysql获取自动生成的主键报错:Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYS to Statement.execu
- UIButton 扩大按钮的响应区域
- easyui表格复选框的全选键是否选中
- 关于UITextView上部出现空白一步解决
- NSOperation和NSOperationQueue
- EF的SqlQuery和EntitySql
- iOS UILabel显示HTML文本
- Incredibuild 中出现Command line error D8037的解决方法
- !!!求教,java进行数据库查询,re.next()为true,但不执行if(re.next())分支
- Android view中的requestLayout和invalidate方法
- POJ2533 Longest Ordered Subsequence
- exception finished with non zero exit value 2