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"

How to spawn blueprint actor from editor

Hi,

So in my header i have

  UPROPERTY(EditAnywhere)     
   UObject* objectToSpawn;

which takes the blueprint And this

  UPROPERTY(EditAnywhere) 
   AActor*  objectSpawnTarget;

to take the target position vector.

So now in my .cpp ... i am unsure how to make it spawn on targeted location... any ideas?

Product Version: UE 4.14
Tags:
more ▼

asked Nov 18 '16 at 02:56 PM in C++ Programming

avatar image

Heng Kok Kuan
13 5 6 7

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Hi All,

So finally.... i may have found what i need. I added this to my header

 UPROPERTY(EditAnywhere, Category = "Our Spawning Object")
 TSubclassOf<UObject> ourSpawnObject;

and used this in my .cpp

 //create spawn params
 FActorSpawnParameters spawnParams;
 //who did the spawn? THIS controller did it
 spawnParams.Owner = this;
 //instigator to default
 spawnParams.Instigator = Instigator;
 UObject* ourNewObject = GetWorld()->SpawnActor<UObject>(ourSpawnObject,objectLocation, FRotator::ZeroRotator, spawnParams);

The whole time i wasn't sure what to put in < > as all the code out there kept pointing me to pointing to a child object of the class , or the class itself. So just by luck i just tried UObject as i remembered Blueprints are UObjects somewhere.

Anyways , if you guys have an easier solution, or spot something i did horribly wrong please let me know!

more ▼

answered Nov 18 '16 at 04:27 PM

avatar image

Heng Kok Kuan
13 5 6 7

(comments are locked)
10|2000 characters needed characters left

Just follow the documentation ;) (and google it at least once..)

Here https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Actors/Spawning/

Good luck ! Best regards.

more ▼

answered Nov 18 '16 at 03:07 PM

avatar image

NymKappa
692 31 20 53

avatar image Heng Kok Kuan Nov 18 '16 at 04:15 PM

Hi Joris,

I now have this in my header

 UPROPERTY(EditAnywhere, Category = "Our Spawning Object")
 TSubclassOf<ASpawner> ourSpawnObject;

and this in my .cpp

 //create spawn params
 FActorSpawnParameters spawnParams;
 //who did the spawn? THIS controller did it
 spawnParams.Owner = this;
 //instigator to default
 spawnParams.Instigator = Instigator;
 ASpawner* ourNewObject = GetWorld()->SpawnActor<ASpawner>(ourSpawnObject,objectLocation, FRotator::ZeroRotator, spawnParams);

Currently it is not spawning my blueprint... but i suspect im getting closer... Its probably is because of the subclass i defined ASpawner TSubclassOf ourSpawnObject;

The problem is how does it know what class type it should be ? and even if i got the class type, how do you actually pass it in < > ??

I don't want to hardcode anything .. as i actually want to allow the editor to be able to spawn any blue print actor i pass to it.

(comments are locked)
10|2000 characters needed characters left
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