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 actors in design stage?

Hi all. So to set the scene, I have a number of .obj models and also files describing where those models should be placed (4x4 matrices, some models are placed multiple times, ...). I also have no experience with c++ (only similar languages) or with unreal engine.

How do I go about automizing the placement of those models in a scene at the design stage, so that I can still move em further around?

I found this tutorial : https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/SpawnAndDestroyActors/Blueprints/ and I think this simply doesn't work anymore in ue 4.16.

I also found this https://answers.unrealengine.com/questions/328407/ive-been-trying-to-spawn-an-actor-in-c-for-the-las.html . Now to call GetWorld(), I'd have to extend something like an actor, so that it can be placed in the world, and getworld can be called. but how can I run that code on my actor at design time?

Also, the question states that I have to "#include the thing I want to spawn". Does this mean that I have to include some kind of genericasset.h header, and pass the name of my model in the FActorSpawnParameters? Or do I have to 'include a model', if such a thing makes sense?

Theres this nice visual interface-programming, how are you supposed to combine it with some c++ scripts? I created a class that defined some functions, but have no clue how I could instantiate said class in the blueprint and call some functions on it.

And how would I preferably go about reading in the positions of all models, should I try to create some kind of csv formatted datatable?

Any help whatsoever would be greatly appreciated.

Product Version: UE 4.16
Tags:
more ▼

asked Jun 19 '17 at 10:05 PM in C++ Programming

avatar image

dinosoep
6 6 5

avatar image dinosoep Jun 20 '17 at 10:01 PM

Small update. I managed to create a c++ class, create a blutility that calls a function in my class, and that function can potentially spawn meshes. The problem is that SpawnActor requires that I pass in the class of the object that I want to spawn, but they're simple objects, they have no class. I really don't want to have to wrap every object in a class...

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

1 answer: sort voted first

Alright, figured it out.

The trick is to create a c++ plugin. You can then spawn static meshes by executing :

 UWorld* const World = GEditor->GetEditorWorldContext().World();
     AStaticMeshActor* newmesh = Cast<AStaticMeshActor>(GEditor->AddActor(World->GetCurrentLevel(), AStaticMeshActor::StaticClass(), FTransform(FVector(0))));
     newmesh->GetStaticMeshComponent()->SetStaticMesh(LoadObject < UStaticMesh>(nullptr, TEXT("StaticMesh'/Game/StarterContent/Props/SM_Chair.SM_Chair'")));
     newmesh->MarkComponentsRenderStateDirty();

I can now create a csv file containing the paths of my objects along with their mat4s, read it in somehow and use the Ftransform to apply the mat4s. Quite neat, all in all.

more ▼

answered Jun 22 '17 at 12:55 PM

avatar image

dinosoep
6 6 5

(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