Spawn actors from BP in c++, with class known from HitResult

Hello! In a current game project I am working on, we want to be able to spawn a blueprint actor identical to the one that has been hit with a ray hit result. I.e. we can get the blueprint generated _C class from GetClass() and the path from GetFullName() (BlueprintGeneratedClass /blah/blah/blah_C). But SpawnActor generates a nullreference and any fiddling with ConstructorHelpers doesn’t work, of course, since this takes place in a non-constructor function. There are several different objects, all derived from a certain base class, so it’s not possible to have a gigantic array with all the types that are possible and sit and match with them.

Is there any way of spawning an object when you already know the class references etc, for a blueprint class? I mean it’s right there, it has been hit by a ray and we have the name, how do we make another one? XD It’s now 3:20 AM and I still can’t figure it out, please help! :slight_smile:

I believe the hit result outparams include an Other object which represents the hit actor from which you can GetClass. It might be named something else but i think it was Other

FHitResult has a method called GetActor(). Then you just have to call GetWorld()->SpawnActor using the output actor’s class.

Thanks. It turns out I was just being stupid. I’ll chalk it up to it being so late. Obviously it wouldn’t spawn because of something being in the way.