# How to Generate an Actor from Class Using C++?

**URL:** <https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166>\
**Category:** C++\
**Tags:** UE4-20, unreal-engine, UE4, question, CPP\
**Created:** [August 3, 2022, 12:03am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166 "2022-08-03T00:03:05Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 3, 2022, 12:03am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/1 "2022-08-03T00:03:05Z")

</div>

Hello, I want to translate this blueprint into `C++` but I am a little bit stuck…

 ![image_2022-08-03_045901289](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/e/6/ce699f868983d14b4bb5c550314e474193239799.png)

```auto
void ATestClass::GenerateItems()
{
	AItemGroup* ItemGroupRef{};
	TArray<FName> OutRowNames{};
	(OutRowNames).Reset();

	if (UDataTable *DT_SpawnLocation = LoadObject<UDataTable>(NULL, TEXT("/Game/Testing/DT_SpawnLocation")))
	{
		OutRowNames = DT_SpawnLocation->GetRowNames();

		for (auto& Array : OutRowNames)
		{
			if (const UDataTable* DT_SpawnLocation{ LoadObject<UDataTable>(GetWorld(), TEXT("/Game/Testing/DT_SpawnLocation")) })
			{
				if (const FST_ItemGroupLocation * OutRow{ DT_SpawnLocation->FindRow<FST_ItemGroupLocation>(FName(Array), "") })
				{
					if (OutRow)
					{
						/*I am Stuck here... */
					}
				}
			}
		}

	}
}

```

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [August 3, 2022, 12:07am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/2 "2022-08-03T00:07:27Z")

</div>

You can use my example in this post:

> [Can't spawn ACharacter c++](https://forums.unrealengine.com/t/cant-spawn-acharacter-c/610304)

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 3, 2022, 12:17am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/3 "2022-08-03T00:17:37Z")

</div>

Thank you sir for reply, but the post doesn’t solved my problem… I am stuck in the node  
 ![image_2022-08-03_051253201](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/e/7/7e7024cc62c44cf57f9093d07494be68f9285eaa.png)

```auto
if (OutRow)
	{
                SpawnActor(); // I don't know how to use this in C++
		OutRow.Location; // I already have this to set in spawnTransform under SpawnActor Node
	}

```

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [August 3, 2022, 12:25am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/4 "2022-08-03T00:25:50Z")

</div>

The spawnActor node can be translated to c++ like this:

> GetWorld()-\>SpawnActor(YourActorClass, SpawnTransform, SpawnInfo);

The full example from the other post:

```auto
// SpawnTransform is the location + rotation + scale (absolute) of the spawn
FTransform SpawnTransform;
// SpawnInfo contains the Collision Handling Override
FActorSpawnParameters SpawnInfo;
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
// Spawn the actor:
// Use your own actor class:
TSubclassOf<AActor> YourActorClass = AActor::StaticClass();
AActor* NewActor = GetWorld()->SpawnActor<AActor>(YourActorClass, SpawnTransform, SpawnInfo);

```

Where exactly do you get stuck?

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 3, 2022, 12:32am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/5 "2022-08-03T00:32:49Z")

</div>

Thank you sir for more detailed reply, but I am still stuck to set the location from the data table.

 ![image_2022-08-03_053140608](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/2/c/42c0969d7bbfb6fb2cda596aa9fe902c7579d908.png)

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 3, 2022, 12:38am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/6 "2022-08-03T00:38:15Z")

</div>

I want to do something like this. I already have the location in the data table.

`MakeTransform(OutRow.Location, FRotator(0.000000,0.000000,0.000000), FVector(1.000000,1.000000,1.000000));`

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [August 3, 2022, 12:44am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/7 "2022-08-03T00:44:44Z")

</div>

There are a few ways you can make an FTransform, in Visual Studio you can see a complete list of overloads.

```auto
FVector YourLocation= YourStruct.Location;
FTransform SpawnTransform = FTransform(YourLocation);

```

For example you can also provide the rotation and scale immediately:

> FTransform(const FQuat& InRotation, const FVector& InTranslation, const FVector& InScale3D)

- If you need to, FQuat can be made from FRotator: FQuat YourQuat = YourRotation.Quaternion()

---

<div class="post-metadata">

**Author:** ![KaidoomDev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaidoomdev/32/977996_2.png) [@KaidoomDev](https://forums.unrealengine.com/u/KaidoomDev)\
**Post date:** [August 3, 2022, 2:04am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/8 "2022-08-03T02:04:52Z")

</div>

You can also use this to create a transform  
`FTransform Trf = UKismetMathLibrary::MakeTransform(OutRow.Location, FRotator::ZeroRotator, FVector(1.f, 1.f, 1.f));`

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 3, 2022, 2:18am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/9 "2022-08-03T02:18:28Z")

</div>

yes, `UKismetMathLibrary` is for Blueprints I maybe

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [August 3, 2022, 11:47am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/10 "2022-08-03T11:47:41Z")

</div>

Kismet libraries are indeed for Blueprints. rarely useful in c++

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 3, 2022, 11:52am UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/11 "2022-08-03T11:52:43Z")

</div>

yes but I don’t want to use them, I want to master pure C++ for UE4.

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [August 3, 2022, 7:30pm UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/12 "2022-08-03T19:30:39Z")

</div>

If you have the whole engine source, I would recommend doing Find In All Files “SpawnActor” and then you can find both the definition of the function and examples of how to use it.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [August 3, 2022, 7:37pm UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/13 "2022-08-03T19:37:55Z")

</div>

yes I am doing this and when I am failed… I come to this forum get help )

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [August 4, 2022, 5:42pm UTC](https://forums.unrealengine.com/t/how-to-generate-an-actor-from-class-using-c/620166/14 "2022-08-04T17:42:00Z")

</div>

I was hoping that would be a tip that would help you find answers in the future 🙂
