Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Unreal Blueprint - passing Constructor arguments for a spawned class

$
0
0
I didn't had much luck so far asking on the Unreal official forum (seems there is not much traffic over there ), so I'll ask my question here as well in the hope that someone knows ^_^' I'm trying to make a Worm game using Unreal mixing C++ and Blueprint, here some of the code I have: struct TArrayBool { TArray<bool> BoolRow; inline bool& operator[](int Column) { return BoolRow[Column]; } }; //Inside the WormGameMode.h //... //This multi-dimensional array holds bool to represent if a block in the grid of the game is already occupied or not //This way I know in which grid blocks I am allowed to spawn Pickups TArray<TArrayBool> GridSlotsOccupiedMap; //Inside the WormGameMode.cpp AWormGameMode::AWormGameMode():AGameModeBase() { //Setup GridSlotsOccupiedMap TArrayBool Temp; Temp.BoolRow.Init(false, GridWidth / GridBlockSize); GridSlotsOccupiedMap.Init(Temp, GridHeight / GridBlockSize); } //This is a BlueprintNativeEvent //It just Toggle the occupied status at a given [row][column] in the map void AWormGameMode::ToggleOccupiedBlock_Implementation(int Row, int Column) { GridSlotsOccupiedMap[Row][Column] = GridSlotsOccupiedMap[Row][Column] == true ? false : true; } As you see when I spawn a pickup I toggle the corresponding bool inside the "GridSlotsOccupiedMap" 2dArray inside the class and then use InitPickupID to store that same ID inside the pickup itself, so when the Worm collide with it and the pickup get destroyed I know which ID on the 2dArray should be toggled again (as allowed starting position for spawned stuff). So my concern here is, is it possible that the SpawnActor by random chance spawns the pickup just in front of my Worm which steps on it before the InitPickupID is executed? If that could happen I wouldn't be able to toggle the corresponding ID on the map thus that slot won't be able to spawn any more pickups. So there is a way for me to pass those informations directly to the Pickup.h constructor so that the ID is recorded before the spawning? BlueprintImageLink

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>