Is there any event after level / world loaded in C++?

Hi guys,
Is there any event after level / world loaded in C++? I want to set some actors randomly just like followering:

// PSEUDO CODE
void onWorldLoaded() {
    World= GetWorld();
    for (size_t i = 0; i < 10; i += 1) {
        Position = RandomPosition();
        Rotation = RandomRotation();
        World->SpawnActor<MyActor>(Position, Rotation);
    }
}

In other words, how could we programming a GodEyesClass,

void GodEyes::beforePlayerEnterGame() {
    // generate initialized Actors in C++
}

void GodEyes::atSomeSpecialTime() {
    // change some Actor
}

Without it, we could only 1) add invisable actor to level as a background worker 2) programming actor 3) this actor do things to implement all I mentioned before which really antilogical, is this right?

Thanks

Perhaps I don’t fully understand the question so forgive me if that is the case.

You can spawn actors whenever you want. A good example of this is found in the first person shooter C++ template shipped with UE4 when you fire the gun.

In this case, if you look in the editor in Project Settings:Input you will see that the action mapping “Fire” has been linked to, among other things, the left mouse button.

If you look in the C++ code in Character.cpp on line 121 there is a PlayerInputComponent->BindAction call that links the “Fire” input to the OnFire function in Character.cpp

If you look through the OnFire code (starting on line 141) you will see that code (in a non-vr situation) determines a rotator (SpawnRotation) and a location (SpawnLocation) then makes a SpawnActor call on line 166 like you contemplate in your pseudocode.

In your example, you could have the call to a function that works like OnFire that is called in the BeginPlay function or some other triggering event and then randomly determine parameters for location and rotation before calling SpawnActor.

Hope this is the help you were seeking.

I would add that there lots of events to choose from including those found here:

(there are ++ equivalents to all of these)

or by using timers

really thanks for your advice, I think function like onBeginPlay() could work, but if I do some heavy jobs at that time (such as for loop in 10K iteration), it will block the game. So the event onWorldLoaded() I need must before game play, is it possible?

The sequence of events for start up is documented here:

The key piece to focus on is this image:

You could certainly start the “work” to prepare the data to spawn the actors in advance but, as you can see, the act of spawning the actors is the last step in the sequence so I don’t think there is a mechanism in UE4 to pre-empt that process.

However, there are things you can do to help:

  1. Make your actors as light-weight as possible (lots of components will slow you down)

  2. If you have time in the game before you need all of the actors live, you could start a process of gradually building up a non-visible pool of actors while other elements of the game are on-going so that when the time came to have all of them live and in the level, it would simply require you to set transform and rotation and then turn visibility on (this is my rudimentary understanding of “object pooling”) - Bruno Xavier (Object Pool Plugin) and Jakob Karulik (Actor Pool Plugin) have tools in the UE Marketplace that you could investigate if you didn’t want to try to write your own.

I think BeginPlay() is what I needed, thanks for your two answers.