Cooking failure when using weak_map and construction script

I think you are misunderstanding the concepts of running code in editor, during compile and during gameplay. GetSession() is a API that only works during gameplay, there is no way to have a session if the game is not even running on a server…

What you are trying to do in your current setu (block of a function at class scope) IS hardcodind a data to the class, and since there is no session available at that compile/cook time, it fails.

If you want to init the things during game/when game starts, you should run that logic only inside entrypoints of game loops (OnBegin for creative devices and on initialize/on simulate when scene graph)…

You just need to do the same, but on different place. Can be on a block{}, or can be on a function, just need to run that part of the code only when session is running to be able to retrieve the actual session ID.

Your “workaround” is just a janky crash-avoidance scenario that depends on the ambient where the code runs, and THAT for example, gives problems, it works because:

  • when running during compile, it fails due to no session existing, does not set the map
  • when running on cook, it fails due to no session, it does not set the map
  • when running on a creative server instance, it has session attached to the verse process and sets the map correctly

But, that is a crazy unecessary workaround for something that should be made properly in another way (like my examples before).

And even if it worked and it returned a valid session during compile or cook, it would not be valid, since it would be hardcoded to that testing session, and not the same as the creative match one…

Session is not a magic key/value, it is the server instance that the code is running (in fact, the game shows a uuid session-id on the corners of the game), that is dynamic and changes on every match, not a thing that is always the same to be hardcoded and work fine like you want.