# Why 'Spawn Actor From Class' node returns actor reference when get class from other node?

**URL:** <https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [April 14, 2018, 1:01pm UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613 "2018-04-14T13:01:40Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![KeungKeung](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeungKeung](https://forums.unrealengine.com/u/KeungKeung)\
**Post date:** [April 14, 2018, 1:01pm UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/1 "2018-04-14T13:01:40Z")

</div>

Look.

 ![237427-d.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/c/8/5c87e502e807dc37b38975fdb849b8894307f7ac.png)

To set material of actor, it needs actor’s primitive component. No problem is in here. BUT,  
When I connect Class pin in Set _Building to Spawn_ to Class pin in _SpawnActor Node_, Return pin doesn’t give reference of actor Floor. So return pin and primitive component pin are disconnected. like this.

 ![237428-dd.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/d/7/5d7525b43aa01c0e7a2863fdfaf71bd32e4fc4c1.png)

And I wanna know why.

---

<div class="post-metadata">

**Author:** ![Vaheva](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vaheva/32/963466_2.png) [@Vaheva](https://forums.unrealengine.com/u/Vaheva)\
**Post date:** [April 14, 2018, 2:17pm UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/2 "2018-04-14T14:17:44Z")

</div>

Hi

Fast answer, actor reference is for whole actor, not for actor mesh. You need to get mesh node from referenced actor to set it material. So get node from Floor (ref.) Get Mesh (can have different name, just this is your mesh in floor actor), then set material.

---

<div class="post-metadata">

**Author:** ![ThompsonN13](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ThompsonN13](https://forums.unrealengine.com/u/ThompsonN13)\
**Post date:** [April 14, 2018, 3:20pm UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/3 "2018-04-14T15:20:41Z")

</div>

It wont connect the return pin because the variable class isnt a set value until runtime. Ao the varibke could in theiry be any class and not all classes have the floor component

---

<div class="post-metadata">

**Author:** ![KeungKeung](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeungKeung](https://forums.unrealengine.com/u/KeungKeung)\
**Post date:** [April 15, 2018, 10:02am UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/4 "2018-04-15T10:02:03Z")

</div>

Thanks. but I wanna put _spawn actor_ and _set material_ nodes to function. And get class from event graph. And also I wanna set reference of Floor to variable and set meterial from that variable. how can I do those things?

---

<div class="post-metadata">

**Author:** ![KeungKeung](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeungKeung](https://forums.unrealengine.com/u/KeungKeung)\
**Post date:** [April 15, 2018, 10:04am UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/5 "2018-04-15T10:04:05Z")

</div>

Thanks. but I wanna put _spawn actor_ and _set material_ nodes to function. And get class from event graph. And also I wanna set reference of Floor to variable and set meterial from that variable. how can I do those things?

ps. “Ao the varibke could in theiry…” Is this sentence typo? or abbreviation?

---

<div class="post-metadata">

**Author:** ![JoSf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JoSf](https://forums.unrealengine.com/u/JoSf)\
**Post date:** [April 15, 2018, 11:29am UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/6 "2018-04-15T11:29:50Z")

</div>

The reason _why_ this happens is because the types of class references aren’t the same. Your BuildingToSpawn might be of type “Actor Class Reference”, or something similar, which is a reference to the class higher up in the class hierarchy. Your Floor Class is derived from Actor, but if you get an Actor Class reference, you can only get components from the Actor class.

And the class “Actor” does not have a floor mesh by default, unlike to your own class, “Floor”.

Meanwhile if you select Floor class from the drop-down of the spawn actor, you will always assign a “Floor Class Reference”.

So, either change the variable type of the class variable to “Floor Class Reference”, either by changing the type of the Set variable before the SpawnActor -node, or use the drop-down in SpawnActor instead. If you want to keep on using “Actor Class Reference”, you need to cast before you can access the floor mesh.

 ![237571-spawnactor.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/e/6/2e6c13023dbc61dec84f97021a1e344103fb07ce.png)

---

<div class="post-metadata">

**Author:** ![Vaheva](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vaheva/32/963466_2.png) [@Vaheva](https://forums.unrealengine.com/u/Vaheva)\
**Post date:** [April 15, 2018, 1:48pm UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/7 "2018-04-15T13:48:10Z")

</div>

With function is a little problem, because as I see, you have to do cast to FloorBP after spawn to get floor mesh. I will do little test, now I’m busy.

---

<div class="post-metadata">

**Author:** ![ThompsonN13](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ThompsonN13](https://forums.unrealengine.com/u/ThompsonN13)\
**Post date:** [April 15, 2018, 2:35pm UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/8 "2018-04-15T14:35:21Z")

</div>

that was a combination of big hands on a small phone and not checking what i wrote closely.

---

<div class="post-metadata">

**Author:** ![Vaheva](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vaheva/32/963466_2.png) [@Vaheva](https://forums.unrealengine.com/u/Vaheva)\
**Post date:** [April 15, 2018, 2:35pm UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/9 "2018-04-15T14:35:31Z")

</div>

Ok, I see only dynamic solution works for function, is set mesh and material, because this is correct way. Here Function screen:

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/6/e/76ed1d3526c61fab738be8ffa27aab29b0116b5d.png)

here is function call

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/0/5/a05c2639b451da9c0004907337c248da4ab9f21f.png)

and here function inputs:

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/2/0/220e01ecba7be3cf1be5ae1f9d44a56250c8e5f5.png)

Actor Floor is empty actor, mesh will be created and material set:

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/2/e/b2e0989b94ffec3c42f07e61e123233809541e2f.jpeg)

You can use it in any other procedural actor, not only floor ofc. Sample is jus start, not production solution.

---

<div class="post-metadata">

**Author:** ![KeungKeung](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeungKeung](https://forums.unrealengine.com/u/KeungKeung)\
**Post date:** [April 15, 2018, 3:21pm UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/10 "2018-04-15T15:21:05Z")

</div>

Lol bootyful.

---

<div class="post-metadata">

**Author:** ![KeungKeung](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeungKeung](https://forums.unrealengine.com/u/KeungKeung)\
**Post date:** [April 15, 2018, 3:23pm UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/11 "2018-04-15T15:23:51Z")

</div>

So… am I have to keep mesh in BP that I am fixing? Not floor BP? If it’s true, I better make floor as component not other BP. That seems not good

---

<div class="post-metadata">

**Author:** ![KeungKeung](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeungKeung](https://forums.unrealengine.com/u/KeungKeung)\
**Post date:** [April 15, 2018, 3:28pm UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/12 "2018-04-15T15:28:38Z")

</div>

You really helps me a lot. Thx. I will try it tommorow. Im wondering to people like U. People like u helps others passionately with no resons. Cool.

---

<div class="post-metadata">

**Author:** ![Vaheva](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vaheva/32/963466_2.png) [@Vaheva](https://forums.unrealengine.com/u/Vaheva)\
**Post date:** [April 15, 2018, 8:30pm UTC](https://forums.unrealengine.com/t/why-spawn-actor-from-class-node-returns-actor-reference-when-get-class-from-other-node/422613/13 "2018-04-15T20:30:49Z")

</div>

It’s up to you. If you need for single blueprint and only change floor material, you must use cast to floor blueprint then get floor mesh. My solution is universal, no idea usable or not, just working. Here many ways to achieve desired effect, but it must follow some rules.
