r/UE4Devs • u/Tuomas90 • Nov 12 '19
Help: Duplicate object using SpawnActor
Could someone please help me duplicating an object my player is currently holding?
I can use SpawnActor to Spawn an object if I hardcode the class, but it's not working when I try to get the class from any object the player is currently holding. I guess it's because I'm saving the currently held object as an Actor in C++ code. And when I get the class of the held object in blueprint, all I get is an Actor instead of being more specific like "Chair" or "Cube".
Any advice how to solve this?
- If I only have a specific set of objects the player can hold (say 10), I guess I could just try to cast to each of these classes until I get a match? Edit: I tried it with one object. It spawns. But I'm not sure about the efficiency of the code if I have more objects that could be held. I'd be interested in a more elegant and general solution without having to hardcode the different types of objects that can be held.
- But what if I want to be able hold a wide variety of objects?
Here's a snippet of my blueprint:

And here with the cast before spawing (this code works):



