首页 > 其他分享 >Unreal属性同步机制

Unreal属性同步机制

时间:2023-06-30 21:14:01浏览次数:79  
标签:同步 ReplicatedMovement nullptr AActor RootComponent Unreal AttachParent Attachmen

因为工作需要,需要整理一下属性复制流程

//复制准备
void AActor::PreReplication(IRepChangedPropertyTracker & ChangedPropertyTracker)
{
	// Attachment replication gets filled in by GatherCurrentMovement(), but in the case of a detached root we need to trigger remote detachment.
	AttachmentReplication.AttachParent = nullptr;
	AttachmentReplication.AttachComponent = nullptr;
    //打包移动相关的属性到ReplicatedMovement结构体中,准备复制
	GatherCurrentMovement();

	DOREPLIFETIME_ACTIVE_OVERRIDE(AActor, ReplicatedMovement, IsReplicatingMovement());

	// Don't need to replicate AttachmentReplication if the root component replicates, because it already handles it.
	DOREPLIFETIME_ACTIVE_OVERRIDE(AActor, AttachmentReplication, RootComponent && !RootComponent->GetIsReplicated());


	PRAGMA_DISABLE_DEPRECATION_WARNINGS
	UBlueprintGeneratedClass* BPClass = Cast<UBlueprintGeneratedClass>(GetClass());
	if (BPClass != nullptr)
	{
		BPClass->InstancePreReplication(this, ChangedPropertyTracker);
	}
	PRAGMA_ENABLE_DEPRECATION_WARNINGS
}

 

打包移动相关属性,包括子对象

//移动属性打包,包括子对象属性打包
void AActor::GatherCurrentMovement()
{
    // 需要复制移动属性 || 包含子对象
	if (IsReplicatingMovement() || (RootComponent && RootComponent->GetAttachParent()))
	{
		bool bWasAttachmentModified = false;
		bool bWasRepMovementModified = false;
        //暂存附加的旧对象
		AActor* OldAttachParent = AttachmentReplication.AttachParent;
		USceneComponent* OldAttachComponent = AttachmentReplication.AttachComponent;
	    //附加复制对象重置为空
		AttachmentReplication.AttachParent = nullptr;
		AttachmentReplication.AttachComponent = nullptr;
        
		UPrimitiveComponent* RootPrimComp = Cast<UPrimitiveComponent>(GetRootComponent());
		//需要物理模拟,打包物理属性进行同步
        if (RootPrimComp && RootPrimComp->IsSimulatingPhysics())
		{
			FRigidBodyState RBState;
			RootPrimComp->GetRigidBodyState(RBState);

			ReplicatedMovement.FillFrom(RBState, this);
			
			// Technically, the values might have stayed the same, but we'll just assume they've changed.
			bWasRepMovementModified = true;
		}
        //如果存在根组件
		else if (RootComponent != nullptr)
		{
			// If we are attached, don't replicate absolute position, use AttachmentReplication instead.
			if (RootComponent->GetAttachParent() != nullptr)
			{
				// Networking for attachments assumes the RootComponent of the AttachParent actor. 
				// If that's not the case, we can't update this, as the client wouldn't be able to resolve the Component and would detach as a result.
				AttachmentReplication.AttachParent = RootComponent->GetAttachParent()->GetAttachmentRootActor();
				if (AttachmentReplication.AttachParent != nullptr)
				{
                    //复制移动修正属性到AttachmentReplication
					AttachmentReplication.LocationOffset = RootComponent->GetRelativeLocation();
					AttachmentReplication.RotationOffset = RootComponent->GetRelativeRotation();
					AttachmentReplication.RelativeScale3D = RootComponent->GetRelativeScale3D();
					AttachmentReplication.AttachComponent = RootComponent->GetAttachParent();
					AttachmentReplication.AttachSocket = RootComponent->GetAttachSocketName();

					// Technically, the values might have stayed the same, but we'll just assume they've changed.
					bWasAttachmentModified = true;
				}
			}
            //如果自身就是根组件
			else
			{
				ReplicatedMovement.Location = FRepMovement::RebaseOntoZeroOrigin(RootComponent->GetComponentLocation(), this);
				ReplicatedMovement.Rotation = RootComponent->GetComponentRotation();
				ReplicatedMovement.LinearVelocity = GetVelocity();
				ReplicatedMovement.AngularVelocity = FVector::ZeroVector;

				// Technically, the values might have stayed the same, but we'll just assume they've changed.
				bWasRepMovementModified = true;
			}

			bWasRepMovementModified = (bWasRepMovementModified || ReplicatedMovement.bRepPhysics);
			ReplicatedMovement.bRepPhysics = false;
		}
        //如果Movement数据有修改,make dirty
		if (bWasRepMovementModified)
		{
			MARK_PROPERTY_DIRTY_FROM_NAME(AActor, ReplicatedMovement, this);
		}
        //如果关联对象有修改,make dirty
		if (bWasAttachmentModified ||
			OldAttachParent != AttachmentReplication.AttachParent ||
			OldAttachComponent != AttachmentReplication.AttachComponent)
		{
			MARK_PROPERTY_DIRTY_FROM_NAME(AActor, AttachmentReplication, this);
		}
	}
}

 

标签:同步,ReplicatedMovement,nullptr,AActor,RootComponent,Unreal,AttachParent,Attachmen
From: https://www.cnblogs.com/billin/p/17517814.html

相关文章

  • Java 事务管理@Transactional注解rollbackFor回滚属性,事务的传播行为propagation(REQUI
    事务管理Java事务管理@Transactional注解rollbackFor属性所有的异常都回滚;事务的传播行为propagation(REQUIRED,REQUIRES_NEW)01.事务是一组操作的集合,它是一个不可分割的工作单位。事务会把所有的操作作为一个整体,一起向数据库提交或者是撤销操作请求。所以这组操作要么同时......
  • docker部署mysql主从同步
    1. 规划主机ipmaster10.0.0.1slave10.0.0.12. 查看镜像,下载镜像,导入镜像的命令docker imagesdocker pullmysql:5.7dockerload-imysql.tar3. 启动镜像服务 dockerrun-d --namemysql-master -p3306:3306 -eMYSQL_ROOT_PASSWORD=root@1234 mysql:5.7.174. 复......
  • ubuntu ntp服务(时间同步服务)
    aptinstallntp开启ntp服务器步骤编辑配置文件sudovim/etc/ntp.conf增加内容restrict0.0.0.0mask255.255.255.255nomodifynotrap作用:允许外网所有client(0.0.0.0代表任意IP,如果限制局域网那么更改对应网段)连接到这台服务器同步时间,但是拒绝他们修改服务器时间systemctls......
  • AP8505高压同步整流 5V150mA非隔离电源ic
    深圳市三佛科技有限公司AP8505高压同步整流5V150mA非隔离电源icAP8505基于高压同步整流架构,集成PFM控制器以及500V高可靠性MOSFET,用于外部元器件极精简的小功率非隔离开关电源。AP8505无线门铃芯片内置500V高压启动,实现系统快速启动、超低待机功能。5V非隔离无线门铃芯片AP8505提......
  • PMSG永磁同步发电机并网仿真模型 主要包括发电机、整流器、逆变器(双pwm控制)、电网、控
    PMSG永磁同步发电机并网仿真模型(1)主要包括发电机、整流器、逆变器(双pwm控制)、电网、控制、显示等部分;(2)风机最大功率跟踪mppt采用最佳叶尖速比法;(3)机侧控制(发电控制):采用转速、电流双闭环控制,均采用PI,磁链解耦;调制策略采用SVPWM;(4)网侧控制(并网控制):采用电压、电流双闭环控制,均采......
  • 永磁同步电机(PMSM)模型,一共有两个,分别是基本型永磁同步电机模型(B_PMSM)和磁饱和型永
    自己搭建的Simulink永磁同步电机(PMSM)模型,一共有两个,分别是基本型永磁同步电机模型(B_PMSM)和磁饱和型永磁同步电机模型(S_PMSM)。两者的区别是前者电机参数是定值,后者部分电机参数是变值(由Id和Iq共同决定)。两个模型都是按照定子电压方程+磁链方程+转矩方程+运动方程四个方程......
  • 带负载转矩观测器的永磁同步电动机控制方法。 负载转矩观测器无论是对静态的负载变化
    带负载转矩观测器的永磁同步电动机控制方法。负载转矩观测器无论是对静态的负载变化还是动态的负载变化都有很好的观测效果。一方面可以较好的跟踪负载转矩的变化,另一方面可以作为前馈减小电机转速的波动。原创文章,转载请说明出处,资料来源:http://imgcs.cn/5c/672148599043.html......
  • 基于自抗扰控制器ADRC的永磁同步电机FOC 转速环采用ADRC,和传统PI进行对比来分析ADRC控
    基于自抗扰控制器ADRC的永磁同步电机FOC1.转速环采用ADRC,和传统PI进行对比来分析ADRC控制性能的优越性。对ADRC中的ESO进行改进,进一步提高了ADRC性能。2.提供算法对应的参考文献和仿真模型仿真模型纯手工搭建,不是从网络上复制得到。仿真模型仅供学习参考重新表述:本文研究了基......
  • 三菱Fx3U三轴定位控制程序,其中两轴为脉冲输出同步运行360度转,3轴为工作台丝杆
    三菱Fx3U三轴定位控制程序,其中两轴为脉冲输出同步运行360度转,3轴为工作台丝杆。1.本程序结构清晰,有公共程序,原点回归,手动点动运行,手动微动运行。报警程序,参数初始化程序等。2.自动程序,有绝对位置控制,与相对位置控制程序3.程序中使用到的计算程序全部使用St语言与FB.函数块,逻辑......
  • 基于一种低通滤波反电势观测器的永磁同步电机无感FOC
    基于一种低通滤波反电势观测器的永磁同步电机无感FOC采用的反电势观测器相比传统的SMO、龙伯格等反电势观测方法,在算法结构上更加简单,参数调节容易,只有一个参数。1.提供算法对应的参考文献和仿真模型;2.提供该算法对应代码,可直接移植到CCS中实现实验验证;原创文章,转载请说明出处,......