Why 'Spawn Actor From Class' node returns actor reference when get class from other node?
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.
And I wanna know why.
asked Apr 14 '18 at 01:01 PM in Blueprint Scripting
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.
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
answered Apr 14 '18 at 03:20 PM
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.
answered Apr 14 '18 at 02:17 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here