# How can I spawn an actor sphere without bluprints?

**URL:** <https://forums.unrealengine.com/t/how-can-i-spawn-an-actor-sphere-without-bluprints/37961>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [August 8, 2015, 6:46pm UTC](https://forums.unrealengine.com/t/how-can-i-spawn-an-actor-sphere-without-bluprints/37961 "2015-08-08T18:46:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![i73](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@i73](https://forums.unrealengine.com/u/i73)\
**Post date:** [August 8, 2015, 6:46pm UTC](https://forums.unrealengine.com/t/how-can-i-spawn-an-actor-sphere-without-bluprints/37961/1 "2015-08-08T18:46:23Z")

</div>

Hey guys, I have been looking for quite a while on how I can go about spawning an actor for unreal 4.8 and I cannot find anything. Can someone please explain how to do it? I don’t know the diffrence between a “CreateDefaultSubobject” and was trying that for a few hours.  
Thanks,

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [August 8, 2015, 8:07pm UTC](https://forums.unrealengine.com/t/how-can-i-spawn-an-actor-sphere-without-bluprints/37961/2 "2015-08-08T20:07:43Z")

</div>

Hey, to spawn an actor in C++ you can use the following code (change it for your needs).

```auto

FActorSpawnParameters SpawnParams; // You can add SpawnParamater similar to the one i did below. There are a few more!

SpawnParams.bNoCollisionFail = true;

// You can either spawn them only with GWorld, or use a Pointer to directly save the reference to it. 
// Make sure the Class you spawn, the Template Parameter <..> and the Item Type do match

// So, "YourClass" is the Name of the Class i'm spawning here. You can change "FVector" and "FRotator" with the SpawnPoint and Rotation you want to use
YourClass* Spawned_Actor = GetWorld()->SpawnActor<YourClass>(YourClass, FVector, FRotator, SpawnParams);

```

But i have no idea how to spawn a Sphere with that. If you have the Sphere Class, you can just use it for the “YourClass”.  
You may want to look up how to get the Sphere Class. :X

---

<div class="post-metadata">

**Author:** ![i73](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@i73](https://forums.unrealengine.com/u/i73)\
**Post date:** [August 8, 2015, 8:16pm UTC](https://forums.unrealengine.com/t/how-can-i-spawn-an-actor-sphere-without-bluprints/37961/3 "2015-08-08T20:16:02Z")

</div>

Question:

```auto

YourClass* Spawned_Actor = GWorld->SpawnActor<YourClass>('I don't know what goes here', FVector, FRotator, SpawnParams);

```

i don’t fully understand the hierarchic of unreal, are the classes instances of actors? In unity you make a “Prefab” and then you can add a class to it, but is it the other way around for unreal?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Mhousse1247](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mhousse1247](https://forums.unrealengine.com/u/Mhousse1247)\
**Post date:** [August 8, 2015, 9:00pm UTC](https://forums.unrealengine.com/t/how-can-i-spawn-an-actor-sphere-without-bluprints/37961/4 "2015-08-08T21:00:14Z")

</div>

UE4 is totally diffeent from Unity in how they handle compoenents

In unity a prefab is a “GameObject” and we use

```auto

 Instantiate(Prefab,Location,Rotation) 

```

to spawn it

In UE4 an equivalent (Not Really) of GameObject is an “Actor”

Exemple you can create a new Class MyActor derived from AStaticMeshActor  
AStaticMeshActor = AActor + UStaticMeshCompoent

FVector Location;  
FRotator Rotation;

```auto

GetWorld()->SpawnActor<AMyActor >(AMyActor ::StaticClass(), Location, Rotation);

```

if you want a similar way to how you do in unity , you can fill “MyClass” in the editor with a Blueprint Actor for exemple

```auto

.h
UPROPERTY(EditAnywhere)
UClass* MyClass;

```

```auto

.cpp
GetWorld()->SpawnActor<AActor>(MyClass, Location, Rotation);

```

(PS: You may find some errors here , I’m using my phone)

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [August 8, 2015, 10:04pm UTC](https://forums.unrealengine.com/t/how-can-i-spawn-an-actor-sphere-without-bluprints/37961/5 "2015-08-08T22:04:18Z")

</div>

> [@i73;351489](#):
>
> Question:
> 
> ```auto
> 
> YourClass* Spawned_Actor = GWorld->SpawnActor<YourClass>('I don't know what goes here', FVector, FRotator, SpawnParams);
> 
> ```
> 
> i don’t fully understand the hierarchic of unreal, are the classes instances of actors? In unity you make a “Prefab” and then you can add a class to it, but is it the other way around for unreal?  
> Thanks!

No, other way round. A Class is the “template” to create lots of actors. For example you have a Class for your Character. It has all the Variable and Functions as well as Blueprint Components  
that your PlayerCharacter should have. Then you can spawn multiple actors/instances of it.

In Unity, you do this differently and i highly recommend to stop thinking in Unitys kind of way. I also did this and this is just not how UE4 works.  
You will not add classes or C# Scripts to a prefab but just put the whole logic into the C++ Class.

You may want to learn C++ a bit first before entering UE4. Then it makes much more sense. This is not a UE4 setup, this is basic C++ (:

EDIT: This will help you, although i would not say that Prefabs are Blueprints. Blueprints are just Visual Scripting ChildClasses of C++ Classes.  
C++ ChildClass is no difference to a BP Child Class. Just that you are working a bit more limited and in a visual editor. So not really a prefab  
thing like in Unity:

> **[Unreal Engine for Unity Developers](https://docs.unrealengine.com/5.3/en-US/unreal-engine-for-unity-developers/)**
>
> Learn how to get started with Unreal Engine 5 if you previously used Unity.

---

<div class="post-metadata">

**Author:** ![i73](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@i73](https://forums.unrealengine.com/u/i73)\
**Post date:** [August 8, 2015, 10:24pm UTC](https://forums.unrealengine.com/t/how-can-i-spawn-an-actor-sphere-without-bluprints/37961/6 "2015-08-08T22:24:58Z")

</div>

Thatnks! So I understand that, but how does MyClass become an actor?  
so basically what I am being told is I want to spawn a class that “Holds” an actor to it? Why don’t I just spawn an actor?

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [August 8, 2015, 10:29pm UTC](https://forums.unrealengine.com/t/how-can-i-spawn-an-actor-sphere-without-bluprints/37961/7 "2015-08-08T22:29:51Z")

</div>

> [@i73;351563](#):
>
> Thatnks! So I understand that, but how does MyClass become an actor?

The Engine is spawning it at the given “FVector” position and with the given “FRotator” rotation and with the given “FActorSpawnParameters” like i showed you above.  
The function to spawn it is part of the UWorld object. That’s why you call “GetWorld()” and from that pointer you call “GetWorld()-\>SpawnActor…” etc.  
This function will return a pointer to the spawned actor that you can save to a variable to use it later on. Just like i posted it in my post above.

(Note: I accidentally wrote “GWorld-\>” instead of “GetWorld()-\>”. Sorry about that! Fixed it up there in my first post.)

---

<div class="post-metadata">

**Author:** ![i73](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@i73](https://forums.unrealengine.com/u/i73)\
**Post date:** [August 8, 2015, 10:59pm UTC](https://forums.unrealengine.com/t/how-can-i-spawn-an-actor-sphere-without-bluprints/37961/8 "2015-08-08T22:59:37Z")

</div>

> [@eXi;351567](#):
>
> The Engine is spawning it at the given “FVector” position and with the given “FRotator” rotation and with the given “FActorSpawnParameters” like i showed you above.  
> The function to spawn it is part of the UWorld object. That’s why you call “GetWorld()” and from that pointer you call “GetWorld()-\>SpawnActor…” etc.  
> This function will return a pointer to the spawned actor that you can save to a variable to use it later on. Just like i posted it in my post above.
> 
> (Note: I accidentally wrote “GWorld-\>” instead of “GetWorld()-\>”. Sorry about that! Fixed it up there in my first post.)

Thanks so much and sorry if I’m \*\*\*\*\*\*\* you off 😛

So this is what I have:

```auto

.cpp:
FActorSpawnParameters SpawnParams; // You can add SpawnParamater similar to the one i did below. There are a few more!
SpawnParams.bNoCollisionFail = true;
FVector NewLocation = FVector(0.f, 0.f, 300.f);
ASpawnFactory* Spawned_Actor = GetWorld()->SpawnActor<ASpawnFactory>(MyClass, NewLocation, FRotator::ZeroRotator, SpawnParams);

.h:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Pickup)
UClass* MyClass;

```

I am not familiar with how I can turn MyClass into a sphere, that was the question I was asking. Do I have to make a Class with an attached component in unreal editor? Do I have to make a Class and use a mesh component in the c++ attached to it? I am confused as to how I make “Meshes” in unreal. I am not confused about the logic.
