ue4 代码根据某个物体生成(复制)物体

1、定义根据哪个物体生成

	UPROPERTY(EditAnywhere,Category="SpawnObj")
	TSubclassOf WhatToSpawn;

2、

void ACollectActor::TestSpaw()
{
	UWorld* const World = GetWorld();
	if (World)
	{
		FActorSpawnParameters SpawnParams;
		SpawnParams.Owner = this;
	//	SpawnParams.Instigator = GetInstigator();

		FVector SpawnLocation = FVector(1, 1, 1);

		FRotator SpawnRotator;
		SpawnRotator.Yaw = FMath::FRand()*360.f;  //y
		SpawnRotator.Pitch = FMath::FRand()*360.f;  // z
		SpawnRotator.Roll = FMath::FRand()*360.f; // x

		AActor* const SpawnedPick = World->SpawnActor(WhatToSpawn, SpawnLocation,
			SpawnRotator, SpawnParams);

	}
}

3、 调用 TestPawn,然后在场景中(或继承这个类的蓝图)对WhatToSpawn赋值

你可能感兴趣的:(UE4,ue4)