Looking to increase my knowledge of programming in UE5. I’m creating data transfer between levels atm and I’m casting quite a bit to get the relevant data to transfer (inventory, player stats, level etc). I’m worried about dependency chains. Do they persist between levels? Or is it a new state?
Is casting to the game instances bad? Since it is consistent across the entire game?
I assume casting from your player is fine since both the GI and Player are constantly loaded.
I’ll be using structs to send large strings of data, but where should these be split and set? In the GI or in the individual blueprints?
Could I keep game long values in the game instance (player Level + EXP, for example)?
casting doesnt matter if they’re common classes that are always loaded. ie your playercontroller, pawn, gamemode etc, assuming they don’t change in different gamemodes, that said it may be better to do that in the gamemode so you have the option to change them later.
depends what your casting too, ie a player shouldnt reference/cast to say a grenade, which then has explosion particles/sound FX etc.
for single player thats likely fine, common practice would likely be the playerstate/pawn but that depends on your game
like this doesnt matter, as long as whatever references it needs it.
in short, cast to your common game classes but make sure those dont pull in references to outside things.
for instance have a character base class with no mesh. so when you cast to the baseclass it doesnt load meshes/materials etc
usually between levels things get destroyed, if there a no references it will get garbage collected (unloaded) so it just depends if anything references it.
you probably dont need your game instance referencing things but as said if its always loaded it doesnt really matter