How to make two actors communicate
Hello! I want to know whats the best way to have one actor communicate with another? I've started working with UE4 very recently and I'm still very new to it. What I want to make is a tree actor that, once it is interacted with by the player, it would communicate with a coconut actor and enable its physics. Basically, when the player interacts with the tree by pressing a button, the coconuts will fall down. I've already implemented an interaction system thanks to a tutorial that I have found on Youtube, but I've failed to decipher the method to have the tree actor tell the coconut actors to enable their physics once the player has interacted with the tree. I'm very new to UE4 and I would really like to get some help and guidance of any kind! Would be much appreciated! Thank You.
The blue wire/pins are object references and by plugin them to target input you calling function node on them. You actor is no different. So you need a reference and there countless methods to get one depending what object you trying to access.
You spawning the cocco nut right? Then Spawn Actor node outputs referenced to spawned actor, it gives None if actor failed to spawn. From that pin you can make calls on spawned actor. If you want to continue interacting with actor in that blueprint you need to make object variable of type of you actor (note that blueprint is a object class same as C++ class) and set it with output of Spawn Actor so oyu can keep it for later
If Cooconut is pre-placed on level, you need to make varable in tree and make it "Instance Editable", if oyu have multiple of them then create array. Now you can see varbale in property editor when you click the tree and you can set that variable for that instance of actor and your code can make calls to it.
Note that some nodes return objects in different type then class you getting (most common class they can have), for example Get Game Mode will return GameMode, but since you know that GameMode is your class you can cast it to it and do calls on your blueprint
I made video way back explaining objects and classes in UE4, it might help you understand things more
answered Apr 29 '19 at 01:33 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here