Hi, I’m a super newbie, and I am making a simple checkers game with BPs only, as an introduction to game-making generally and UE4 specifically.
Currently, all I have is a board and pieces - on pressing a key, 12 pieces per side are spawned in the starting locations, coloring themselves based on the controlling player (which for now is just a label - p1 or p2).
I have posted an image of the Piece BP network, which toggles a glow effect on and off when clicking on that piece. My question is, if I click on one piece and then a different piece, how do I tell the previously selected piece to turn off its glow effect? Presently, the only way to turn off a piece is to click it again, meaning multiple pieces can be selected at once. I’m only dealing with a glow material effect because I recognize that once I have event handling straightened out I’ll be able to deal with everything else about the game logic.
You can see in the image that I have created an event dispatcher and then called and bound it in the same BP. My assumption is that since 24 pieces are spawned as copies of one BP, then 24 instances of that BP are running in the game: 23 instances will respond to the 1 instance that dispatches the event. However, this does not work as I expect in practice; instead nothing happens besides the normal single-target toggle on/off, allowing multiple pieces to still be selected. Is there something I’m missing about the way BPs and events work together? How do I code a BP to interact with other instances of itself, especially since none of the pieces are placed in the level editor (they are spawned at run-time)?
I also have a more general question about data and logic structure in a UE4 project:
- Eventually, I am going to add other board games like chess and go, as separate levels reusing the board and the base “Piece” class. I would like to keep all the game-agnostic logic, like keeping track of which piece is selected, on the pieces themselves or in the Game Mode BP. However, all the examples of events and BP communication in the docs use the Level BP as part of the communication pathway. Is there a particular reason for using the Level BP instead of the Game Mode BP? I would like to avoid repeating basic interaction code for every game, since each level will be a different game with different rules.
I hope this isn’t too much to ask at once, but I only have limited programming experience, so I’m not familiar with OO design patterns or how to structure anything more complex than a simple python module! Any help getting me over this mental obstacle will be enormously appreciated!!