I’m trying to communicated with Blueprints which are not in the level by default, nor spawned at the moment of interaction. I have searched for hours, but just can’t figure this out.
In my particular case I have 10.000 bananas which inherit their variables from a parent (fruits) actor blueprint and are spawned dynamically at runtime. Those bananas may be picked up, and stored in my inventory. From my inventory I may select a specific banana and use it.
On use I want
- A: The character controller to
trigger a event related to that
- B: The character controller to be
able to send events back to the
I think the proper function for this are event dispatchers, however my problem is to reference the specified banana. The only option I see is to use “get all actors of class” but getting 10.000 actors and checking if they just were used can’t be right. There must be a way to reference the “dispatching banana” or any other more valuable method.
I really need some help with this.
Have you tried a custom event? You can add references to the actors you’re interested in as parameters in the event.
I tried it now. As far as I understand custom events (at the moment not to much), they would be a valuable option. However just like with the event dispatchers I don’t know how I actually would add the reference to the triggering banana and set it as target when I call the function within the character controller (or any other bp).
My pathetic attempt as attachment (door=banana)
Ah - in this case you could just drop down a cast node and call a function.
I would make all pickupable actors either be children of some pickup actor class or implement a pickup interface. Then you can implement the “onUse” function you will have declared in your interface/parent. This approach is quite generic as you could then “use” any item you wanted.
If you can safely assume all inventory items are of type fruit then you can just cast the inventory item to a fruit and call use.
The dispatchers main use would be if you wanted to be notified every time the banana was used, but it seems you sort of want the opposite. I am assuming that you have some pointer to the banana at the time you want to use it
Alright, thank you! With your hints I actually managed to fiddle things together. I’m not certain yet about various things, but I could solve the Issues behind this Question.
Thank you for this outline, it answered a question that yet had to come to my mind. However, 2 things:
1: Whenever I place a cast to child node, or call a child function in the parent, the BP won’t compile correct (it does compile and function correctly ingame, but draws warnings and “dirty, needs to recompile”. After closing and opening the Project, this is gone, until I click the Compile Button again, as it becomes dirty again. Is there something specific to casting to childs or call child functions?
2: As seen in the Screenshot I’m using a very basic setup, which will work for only a few types of fruits (bananas, apples, oranges). Could you give me some advise, how to setup this for like 1000 types of fruits?