How to make player describe an object?

I want to make my player describe an object with audio when I press a button within the trigger space. Just like in old adventure games like Monkey Island or Discworld. Something like, player walks in the object’s trigger box (let’s say it’s a banana), presses E or any other button, and an audio plays (“this is a banana”).

It would also be interesting if I could assign a few different answers for every time the button is pressed, like “I told you it’s a banana” or “mmm banana” and have them cycle or randomly play.

Thanks for your help!

For something very basic, create an array with sound cues and get Random Int in Range when interacting with the object, the index can fetch a corresponding element from a sound array.

At a more global level, you’d want a struct that defines the object and a DataTable to hold the struct data. This way you can set up all data more easily.

Your answer got me in a better path. I now knew what to look for in tutorials and in the engine.

However, I found that when I assign a sound in the level blueprint, it plays when I hit the button in any place in the level and not only when I am within a specific object’s trigger.

I am not very experienced with blueprints even though I get better every day. Everyone in tutorials seems to go to the Level Blueprint to make things work, but they always make ONE thing, so I guess I’m missing something about object-specific interactions. Do you have any idea what it is I’m doing wrong? Thanks!

You need to think about objects.

  • create an actor that has an array of sounds, populate it with the sounds you need
  • place the actor in the level or spawn in
  • in the player controller: GetHitUnderCursorForObjects will allow you to obtain object’s reference by clicking it
  • check distance to object (length of object vector - player vector)
  • compare the above result with the min necessary distance
  • if the comparison is True, pick random sound and play it

So this would be your Object, it has a cube to click on and a Custom Event to play random sound from the array:

And your Player Controller can handle clicks on the world objects like so: