The first thing if you want to handle Use options within Blueprint, is to set “Blueprint Multi Use Entries” = true on your object.
Then specifically as an example, this modified Storage Box adds a new Use menu option for “Increment Number #” to that box, which each time you activate it, increases a number that is printed to the Use String. That number is networked from the server, and saved into the savedata of that object. The relevant overriden Blueprint functions in that object, visible in its blueprint graph, are:
Implementable Functions:
“BP Get Multi Use Entries”: This is the most important function, where you are given a list of “Multi Use Entries” (from native code), and you can parse these, add to them, remove from them, or change their “Use Index” values to new numbers so that you can manually handle them in Blueprint. Any new Multi Use Entries that you add should be given unique Use Index values for your Object, so probably best to start above 5000 (they only need to be unique within an object, so you don’t have to worry about conflicting with other Mods). It’s the unique Use Index codes that will allow you to handle the Use action in the “BP Try Multi Use” function (which is server-side) and the “Event BP Client Do Multi Use”, which is client-side on the client that used the object (less common, primarily just for any UI feedback local to that client, such as opening a UI – most of the time if you want to do something you’ll do it specifically on the server). Make sure to pass your modified array out from the function, as I do. Only entries returned on the array will be shown for the client to actually use! You can think of this function as getting a list of “what are things a specific client can use on this object” – the client will see this returned on its user interface. Note that this function is run on both client AND server, and is assumed that both client and server have the necessary synchronized state to return the same “Multi Use Entries” values, which you can achieve by Replicating variables as necessary for custom state logic.
“BPTry Multi Use”: This is where you’ll handle the “Use Index” values for a specific client, on the server. You can think of this function as actually DOING the use action for a specific “Use Index”, on the server specifically. If you return “True” from this function for a specific “Use Index”, then the client will get a “Event BP Client Do Multi Use” fired locally on the Using client, as a sort of client-side “confirmation” that the “Use” action was successful (optional, you don’t have to return true and thus you can just do all necessary response to the Use on the server if you want).
Implementable Event (in the Event Graph):
“Event BP Client Do Multi Use”
This event is triggered on the client with the corresponding “Client Use Index”, which you can then handle on the client for any local feedback specifically onto the person/client who used that.
Note that you could also manually remove existing Use entries by searching the “Multi Use Entries” array within the “BP Get Multi Use Entries” function for specific “Use Index” number codes (you can debug Blueprint to find out relevant number codes), and either removing those entries or changing their number codes to something that you’ll handle in blueprint.
Anyhow, it’s hopefully fairly self explanatory when you examine that Storage Box’s blueprint in detail – its implementation of those 2 functions and Event in its blueprint – and of course the exact same functionality works on PrimalCharacters as well. Combining this with manipulation of their InventoryComponent and CharacterStatusComponent, as well as modifiction of replicated & saveable variables, and existing editable variables (which can if necessary be replicated by mirroring them as replicated variables), you can do just about anything with the “Use” system in blueprint now!
Have fun and happy modding, more things are coming including many more Game Functions wrapped into Blueprint!
-Drake