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