ue 小知识点 spawnactor的 时候

44 篇文章 19 订阅

AActor* UWorld::SpawnActor( UClass* Class, FTransform const* UserTransformPtr, const FActorSpawnParameters& SpawnParameters )

1、editor状态下生成了一个guid

#if WITH_EDITOR
	// Generate the actor's Guid
	FGuid ActorGuid;
	if (SpawnParameters.OverrideActorGuid.IsValid())
	{
		ActorGuid = SpawnParameters.OverrideActorGuid;
	}
	else
	{
		ActorGuid = FGuid::NewGuid();
	}

 newguid 方法 会调用 FGenericPlatformMisc::static void CreateGuid(FGuid& Result);

每个平台都不一样。

2、生成了一个唯一的actor name

跟now 和 mac 地址有关

	

NewActorName = FActorSpawnUtils::MakeUniqueActorName(LevelToSpawnIn, Template->GetClass(), BaseName, bNeedGloballyUniqueName);


FName NewActorGUID(FName BaseName)
	{
		uint8 HighPart[9];

		const FDateTime Now = FDateTime::Now();
		check(Now > Origin);

		const FTimespan Elapsed = FDateTime::Now() - Origin;
		const uint64 ElapsedUs = (uint64)Elapsed.GetTotalMilliseconds() * 1000 + (Counter++ % 1000);

		// Copy 48-bits MAC address
		FMemory::Memcpy(HighPart, MacAddress.GetData(), 6);
		
		// Append the high part of the timestamp (will change every ~17 minutes)
		const uint64 ElapsedUsHighPart = ElapsedUs >> 30;
		FMemory::Memcpy(HighPart + 6, &ElapsedUsHighPart, 3);

		// Make final name
		TStringBuilderWithBuffer<TCHAR, NAME_SIZE> StringBuilder;
		StringBuilder += BaseName.ToString();
		StringBuilder += TEXT("_UAID_");

		for (uint32 i=0; i<9; i++)
		{
			StringBuilder += NibbleToTChar(HighPart[i] >> 4);
			StringBuilder += NibbleToTChar(HighPart[i] & 15);
		}

		return FName(*StringBuilder, (ElapsedUs & 0x3fffffff) | (1 << 30));
	}

3、editor状态下 生成actor的externalpackage

#if WITH_EDITOR
	if (bNeedGloballyUniqueName && !ExternalPackage)
	{
		TStringBuilderWithBuffer<TCHAR, NAME_SIZE> ActorPath;
		ActorPath += LevelToSpawnIn->GetPathName();
		ActorPath += TEXT(".");
		ActorPath += NewActorName.ToString();

		// @todo FH: needs to handle mark package dirty and asset creation notification
		ExternalPackage = ULevel::CreateActorPackage(LevelToSpawnIn->GetPackage(), *ActorPath);
	}
#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值