Search in

Sort by:

Everything C++ Programming

Current Space

Question Status:

All Questions With Answer With Accepted Answer

Quick results

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

How can I spawn a BP Actor using code?

0

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:

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.

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.