UNREAL UE4 - How to Spawn Actor with an actor class variable without error warnings? image attached

Hi, i created an struc and data table to use weapons, it also contains the specific “actor class” for each projectile type to be fired, but i canot connect the actor class variable to “spawn actor” nor promote to variable without this error: “Specifying non-default value no longer exists on node spawnactor” and a red new Var 0.

How can i connect the actor class variable to spawn actor? I already tried to make the variable editable and expose on spawn, also since the newvar0 is in red i tried to add an actor reference to the struct, but it wont show up in the data tables… Here is the BP and errors:

Please help

If you want to use an arbitrary Actor Class in the SpawnActor node and still be able to set a custom exposed variable on spawn you will need to cast the ActorClass variable to a specific type before being able to set the variable.

If the variable is on a base class you could also simply convert the Actor Class Reference from an Actor Class to your Base Class to avoid the cast.

I got same errors when casting with a variable and use this as connection for the actor spawn:

I Will be pressing buttons to change weapon, each weapon must be in a data table, in there i have specified the “actor class” for each weapon (a projectile), for that reason i need to connect a variable to the actor spawn in the BP… it wont be an specific actor defined at the BP, it Will take the actor class from the data table, i already made that process to work… but using a variable to make the class its not working.

Casting an specific actor is not working either, or how do you think it should be done, could you please show a BP image?

thanks

As @GarnerP57 said. You have add cast to [your projectile class] between your actor class variable and spawn actor. Also if your actor class is holding only projectile class and you are using it only here, you can just set the projectile type there and you no longer need any casts.

I sometimes get this issue. What you need to do is unhook your ActorClass getter from the SpawnActor node. This converts the Class pin to a drop down list. Select your class for the list. Then, you can hook up all your outputs again and they will work. Then you should be able to reconnect your ActorClass getter again.

It is not an issue. It is designed this way. The compiler needs to know ahead of time what class it is dealing with in order to assign a value to a specific class. That is what casting is all about. You let the compiler know what type of class you expect it to be and more importantly what it can’t be and it will allow you to work with that particular class before it even exist.

If the SpawnActor node is fed an Actor class variable and during run-time you assign a Car Class with a variable named MaxSpeed this is not known ahead of time and therefore it can’t be assigned without casting first.

If on the other hand the SpawnActor node is fed a Car Class and during run-time you assign a Toyota that is a Car Class you will still be able to assign MaxSpeed because it is already known by the compiler ahead of time.

I had this problem, and i just checked the “Component Replicates” and “Auto Activate” boxes. After that, the error didn’t happen again.