I want to spawn one of several actor sub-classes through a function in order to use different default properties of the parent class without needing to go through a complicated copy function from an abstract class ala UDK. The output from the spawn is then used to put the element into an array for later reference (to avoid the nasty search for all actors of the parent class).
This works.
However, there is some trickery to get it working. Just dragging the input variable “Btn Class” into the SpawnActor node is not enough. If you do that the Return Value is of class “Actor”, which cannot be dynamically typecast back to whatever the input Btn Class variable is (as far as I am aware). To get it to work, before you connect Btn Class into the SpawnActor node you first choose the parent class from the class drop down on the node, and then make the link connection. Doing that reveals the Instigator pin (which is hidden by default).
It’s annoying, but it works, and the game runs fine.
Until you shut the editor down. Next time you load the project, the SpawnActor node has forgotten that BtnClass is a subclass of a element you selected from the drop down box, and the Return Value is once again “Actor”. So the game won’t compile or run until you go back and fix it.
EDIT: As a workaround I can typecast the return value back to the parent class for my application and it still works. However this is only really valid because my subclasses add no variables or functions to the parent class; this will not be true for everyone. So while I’ve managed to get this working without needing to fix the blueprint each time I load the project, the issue needs attention.
We haven’t heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you’re still experiencing this issue, please feel free to post back here with additional information.
While the link does not break as before, the class setting still seems to have an issue. The output object class continues to be some default class that is not the same as the input class - I am forced to typecast it before it works. If I hard code the input class via the drop down the code works correctly without the cast on the output class.
So, no, I wouldn’t say you could mark it as “resolved” just yet.
I have 4.4.3. Additional info:
I have a “main class” which defines variables, functions etc. I then create copies of this class that do nothing other than set default values. The code where I use this is essentially a selector of which of the various sub-classes to load. The input variable into the function is of the type of the main class, but naturally is never the main class itself. The array ‘HActor’ too is of the main class. But only if I set the input of the Spawn node to be the specific subclass does the code actually run; setting the variable to be that subclass and then reading the variable into the node fails to correctly execute the code. It does not produce a warning in the log, but the array is empty.
Actually no, scratch that. It still breaks the link. When I run the game in the editor window it runs. When I try “standalone game” (which forces the thing to recompile) the code does not run. If I hardcode the input by selecting the same subclass as passed into the function from the drop down it works regardless of which execute mode I use.
This node is still bugged. I first have to cast the output to “object” then cast that to the main class, and then it runs in standalone game.