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"

Getting the world context to spawn an actor

I am trying to spawn a group of actors after parsing through a file to get some features which would apply to these actors.

The workflow I'm using is - Parse file -> create objects -> Apply these features to a Mesh object (AActor). I find that the best way to apply these features while spawning an actor would be to use

 FQuat RotationEdge(0.0f, 0.0f, 0.0f, 0.0f);
 FVector origin(0.0f, 0.0f, 0.0f);
 UWorld* World = GEditor->GetEditorWorldContext().World();
 FTransform SpawnTransform(RotationEdge, origin); 
 MeshActor* MyDeferredActor = Cast<AMeshActor>(UGameplayStatics::BeginDeferredActorSpawnFromClass(World, AMeshActor::StaticClass(), SpawnTransform)); 
 
 //-----Make Changes to the MyDeferredActor object-----//
 
 UGameplayStatics::FinishSpawningActor(MyDeferredActor, SpawnTransform);

This code worked well when I was putting all of it in the Actor Component Class and then would drag a point light actor in the editor and add this particular component to it. But now I want it to happen as independent actor spawning.

I am not able to figure out what the world context would be to spawn these actors (Since one of these would be the first actor to be spawned). I tried getting a world context from the GEditor object but that just spawns actors that are visible in the actor list on unreal but not in the editor viewport.

From what I read an actor is always required in the scene to obtain the world context which would be used by other actors to spawn. But then how does the very first actor get spawned?

Is my workflow correct? How should I get the world context so that I can correctly spawn actors?

Product Version: UE 4.18
Tags:
more ▼

asked Nov 07 '18 at 09:29 PM in C++ Programming

avatar image

ishaan95
1 1 3

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

1 answer: sort voted first

Instead of GEditor try the world in the GEngine.

 GEngine->GetWorld();
more ▼

answered Nov 12 '18 at 04:23 PM

Brian Johnstone (suspended)
(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