x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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! :)

Product Version: UE 4.19
Tags:
more ▼

asked Jun 01 '18 at 01:22 AM in C++ Programming

avatar image

Fabelwesen
6 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

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

more ▼

answered Jun 01 '18 at 01:49 AM

avatar image

mightyenigma
3.7k 18 23 20

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Jun 01 '18 at 10:28 AM

avatar image

anatzuka
56 3 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Jun 01 '18 at 12:29 PM

avatar image

Fabelwesen
6 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question