Is the activity in the construction script cooked into the game build?

I place my interactable objects in the game world, in the editor. Therefore, can I do some basic logic, for example, add them to a manager, in the construction script? Will it cook and go into the game build?

I’m not sure if I follow exactly what you’re asking, but yes construction script runs in built versions of the game. It runs anytime the instance of an actor is updated.

1 Like

The function you see, which I posted, can I call that in the construction script?

I’m not sure it does…

I think it runs once during packaging, then no more.

If you want to, for instance, change things each time the level is loaded using construction. I don’t think it will work in a packaged game. You need to put that logic on begin play.

1 Like

Construction is (or at least used to be) editor only. So essentially if you package it wont run…

1 Like

I will test it and get back to you gentlemen. BTW, I am using UE4.27.2.

1 Like

Wow you’re making me question everything I know. I’m sure you’re right, and admittedly I haven’t done it in a long time but it must be a serious Mandela effect, I could swear I’ve built procedural layouts within the construction script. But there you go, the more you learn the less you know!

1 Like

I’m waiting for the results of the @DiliupG experiment :nerd_face:

1 Like

User construction script runs during gameplay for dynamically spawned actor, but only in editor for placed actors.

2 Likes

What you said is true: the construction script does run in the editor and in the packed game, but not all code in the construction script. The GetAllActorsOfClass does not run because there is no guarantee that all other world actors are available, and in my case, where I use sublevel streaming, it does not happen. But all the code that applies to the actor itself does run, like raycasting, detecting the ground, setting the tags etc.

1 Like

Right, but I think that ran when you packaged. The ground didn’t move since then, for instance. :thinking:

Sorry, my mistake in writing. The code does run but will not give a correct output because all sublevels may not be loaded and objects not initialized. So, the code will not return all objects, maybe some.

What do you say? Is that how it will work or is it different?

1 Like

This might be useful for someone…
Unreal Engine Construction Script Guidelines.pdf (231.0 KB)

1 Like

Dead link

1 Like

I uploaded a pdf. Sorry about that.

1 Like

Yeah, general rule is to only adjust self in construction.
Referencing anything beyond self is done on begin play with a timer or delayed call.
Binds on other actors classes definitely need a delay.

Can an actor do a raycast and find things in a level, like the ground, managers, etc., in the construction script?

Not recommended. There’s no guarantee as to what will be loaded or when.

You can use the Level BP to do traces etc to determine when things are loaded and set Booleans. Then have your actor get a reference to the Level BP on Begin Play and do recursive interface calls.

Get generic ref to level bp → BPI request load status (bool).

1 Like

If a level is built with all the actors placed on it, why is it not possible to do a raycast because if the level loads later than the actors, that defeats the purpose of placing them in the editor, so thinking on those lines, why not?
I defeat my own question by what happened, in my game which i give below. My game uses sublevel streaming with player proximity in UE4.27.2 where I place all actors and the player spawn point in the level, and the player spawns automatically when the game is run. In the packaged game, the player is spawned before the level streams in and falls through the floor until I placed a blocking volume underneath the player and moved it to the correct location in the Game manager. How is this even possible becase this the logic built into the engine. Spawning the sublevel on player proximity. So how can the engine spawn the player before the sublevel ground has not set the collisions?

The level instance is not loaded on the client instantly. As soon as you join a server a controller is created and it possesses the assigned pawn. Either in level or spawned using the GM’s default pawn class.

These two are then replicated to you. Meanwhile you are literally still loading the level on your end. No floor, pawn falls through. Most of this takes place less than 500ms of connecting to the server.

Most devs disable character movement by default so the pawn doesn’t fall. Then run checks to determine when the level is loaded enough to enable movement.

My process is to use a “Loading Pawn” which is a Pawn class with a simple scene component. The controller by default loads a loading screen UI that displays an Image.

When the loading pawn has determined the level is loaded it calls an event on the controller which RPC’s the server → Game mode to spawn the real character and possess it. Loading pawn is destroyed, Loading UI is disabled and everything rolls on.

This process doesn’t modify the character nor the GM’s default processes. It’s also great for character customization.

I can get into details and examples tomorrow. 5am here.

2 Likes