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"

How can I spawn a BP Actor using code?

Basically, I have an inventory system where what I have set up is that I have coded the base class for an item (that can be picked up and put into the inventory, which is a TArray) in C++, and have created blueprints based off of it (because it is easier to just drag on the static mesh I want, rather than hard code it in.), and basically when the player wants to drop an item, it raycasts out and finds an the first hitpoint with the ground, and then spawns the actor there. Here is the spawn code:

 auto Actor = GetWorld()->SpawnActor<ItemClass>(Hit.ImpactPoint, FRotator(), params);

(Hit being an FHitResult).

The actor is being spawned, but because its a BP, all the previous information associated with it, (the mesh, other variables, etc) aren't given to it (by default the item is basically nothing), and I was curious if I was able to get the class of the blueprint, from which is stored into the inventory array, and spawn it with all its previous information.

Thankyou in advance.

Product Version: Not Selected
more ▼

asked Jun 13 '14 at 10:00 AM in C++ Programming

avatar image

120 11 11 13

avatar image WCode Jun 13 '14 at 10:33 AM

Hey there i think this qustion has been asked several times before. Am not 100% oon this so am just going to link you to a page and hope it be helpfull to you. https://answers.unrealengine.com/questions/54001/c-spawning-from-a-blueprint.html

avatar image Wafflecopta Jun 13 '14 at 11:50 AM

No, that mostly has to do with a crash by the looks of it.

My issue is that I want to know how to spawn actors from a class that has already been initialized etc.

So for example:I have a class,it is derived from AActor, and it has 2 variables. One is a UStaticMeshComponent, and the other is an FString. I then create blueprints based off this class, and set the variables up. I then place these in my game world.

Now what I want to be able to do is duplicate one of those premade blueprint items ( spawn another actor using GetWorld()->SpawnActor() ) from the class I get in C++, from a ray hitting it, and me getting resulting actor from the FHitResult, with all the variables still intact.

I hope that made sense

avatar image WCode Jun 13 '14 at 01:54 PM

Here is a good example of a item/ inventory system hope it helps. https://answers.unrealengine.com/questions/53689/spawn-blueprint-from-c.html

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

1 answer: sort voted first

Well, WCode solved this one for me (again), basically what I did was adapt https://answers.unrealengine.com/questions/53689/spawn-blueprint-from-c.html into a more dynamic system. Basically, on the item blueprint, you have to set a variable (UBlueprint*) to itself, and when the object needs to be recreated, it just uses

ItemClass* Actor = GetWorld()->SpawnActor((UClass*)ItemInventory[CurrentItem]->bp->GeneratedClass, Hit.ImpactPoint, FRotator(), params);

more ▼

answered Jun 14 '14 at 01:05 AM

avatar image

120 11 11 13

(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