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

Hey! Thanks! Are you up the whole night coding? Like I was many years ago. :slight_smile: :slight_smile:
Looking forward for more on this later. Be well!



As you can see this code is in the construction script of an actor that is placed in the sublevel in the Unreal Engine Editor. All this code runs in the editor as well as the packaged shipping build. I tested it several times.

1 Like

How do you know its running in the packaged game, and didn’t just do it during packaging?.. :thinking:

Why not try a script that does something different every time you run it, like chooses the color of a cube in the level.

If the cube changes color every time you load the level in a packaged build, my theory is shot :rofl:

I’m too old for that anymore. I just have a skewed schedule. Yesterday was a late late late one.

Is your project single player or multiplayer?
If MP, Listen or dedicated?
Are you using World Composition?

Modification to SELF should work fine in CS. Accessing other actors in the level and their data is the issue.

Actors have to be loaded, read from drive and stored in memory, to access data about them. The class executing the code and whether or not it’s client or server-side matters.

1 Like

Right, but this is always an issue, even in editor.

I have no idea about MP :nerd_face:

As far as I know, the code that runs in the cooking process gets all the data required, and then it is cooked with all levels and actors because the game runs without any errors, the player can shoot enemies or pick up objects, and the next time the game is run, the destroyed actors are removed. I can load a checkpoint or start a new game, continue from a checkpoint after the player is killed, etc., etc., which is the main mechanic of the game, and it works perfectly. So even if the code runs in the packaging only, which is what really happens, my objective is achieved. But I will try this randomly changing color cube to see if the code actually runs in the packaged game and get back to you. Thanks for the collaboration.

1 Like

Actors we place in a level are technically spawned at run time. The Level simply stores transforms and class names for what goes where.

Instances of an actor have to be loaded in memory and instantiated in order to reference it. CS will cook a class reference, but no data about the class will be stored. An object reference is essentially a pointer to an address in memory.

For example Get all actors of class will only access what’s loaded in memory and instantiated at the time of execution. You can have 20 instances of a class in a level, but only get 5 results.

I’ll work up a good demo example this weekend.

1 Like

I believe you :smiley:

my game is a single-player FPS. I am using world composition, with sublevel streaming based on the player’s proximity.

Looking forward to this.

True, but when I place my enemies in the level and check the variables i want se they are always correct because I am running them in the construction script. So, theoretically, what is IN THE LEVEL is calculated before beginplay and added to the variables. This is not a speculation. I tested this. My packages game was tested on several machines and ran correctly, updating saves, loading values, restating the game, starting from a checkpoint, etc.

Can I just voice of reason ask - why bother with this?

Just move the code to begin play - and add some proper isValid checking like you should do anyway when accessing any actor.
And thats’s that.

From trying this - you basically have no guarantee that on create will run even when you (or maybe specifically when you) manually spawn in the object.

On destroy doesn’t even work right, so if you are good at what you do you just create your own garbage collector in c++ instead…

And sure, Maybe this works at the level blueprint level - but one can also argue that using level blueprints is bad practice and shouldn’t be done. So it’s kind of a “moo” point…

1 Like

The level blueprint is not used for any coding purposes. The actors are placed in the level manually. all save load and spawn code is in the game instance and game manager, and the respective code for player and Ai in parent blueprints. The level bps are there by design. When you create sublevels, the level blueprints are created. I use a Level Manager to look after spawning and destroying in each sublevel.

Doesn’t really change much of anything - construction/destruction would be good for blueprint accessible garbage collection for instance - but it doesn’t work. (Never has reliably).

So what everyone does is to use begin play and specifically levarage whatever death function you create or custom destruction you need as an interface call - if you want to manually fuss over proper disposal of things via blueprint.

Not saying you can’t do whatever you want - saying that testing it and figuring it out when its going to change on you tomorrow because an epic employee got up on the wrong side of the bed is pointless - since you have Begin Play which will never really change behaviour…

Thanks! What you say makes sense. But I am on UE 4.27.2 and it’s very unlikely that anyone will bother to update anything on this version anytime soon, but what you say is true. I’ll change things around and see if my game still works as it is.

1 Like