Page 1 of 2

Collectible Objects with Conversation & Events

Posted: Wed Sep 02, 2020 9:36 am
by bhavinsavajiyani
Hello!

I have a situation where I have set up a quest which would require the player to collect one object only, out of multiple objects (about 10-15 objects, with unique names & no repetitions).
There's one catch though, that I need a confirmation from the user, before collecting that particular object!
In my scene, I set up one object (parent), which would hold all the collectible objects!
Then, I set up a basic conversation using Dialogue System, which would ask player whether the object should be collected, when player is in proximity of the object and 2 choices would be provided in the response.
I have provided Dialogue System Triggers to every collectible object, and added the action of "StartConversation > OnUse" to each and every one of the collectible objects. Also, every collectible object has collider on it, and isTrigger property of every collider is checked.
Note that all the collectible objects share a common conversation, which I mentioned above.

When player interacts with a collectible object, the conversation would start. That is working perfectly!
What I now want, is that when player chooses one of the responses (for example: "YES" as response), then after that particular response, that particular object, which the player interacted with, should be deactivated and conversation should end, or if player chooses another response (for example: "NO" as response), then the object should remain as is and conversation should end.
I also require the name of the object, which is collected.

I don't know whether that approach is correct, where I am sharing a common conversation across multiple objects.
On one hand, the collectible objects are identical, except they have different names, and all the objects should trigger the same conversation, of confirming the collection, when interacted with, by the player! So due to that, I decided to reuse the same conversation with all collectible objects.
And on the other hand, I require only one object out of those multiple objects to be collected. And as a result of collection of the object, I require the name of object which was collected and that particular object should be deactivated, on confirmation of collection!

Any help would be much appreciated!

Kind Regards,
Bhavin!

Re: Collectible Objects with Conversation & Events

Posted: Wed Sep 02, 2020 1:22 pm
by Tony Li
Hi!

Add a Dialogue Actor component to each object. Set the Actor field to the name of the object. Assign the object to its Dialogue System Trigger's Conversation Conversant.

In the conversation, when the player selects YES to pick up the object, use this sequence to deactivate the object:

Code: Select all

SetActive([var=Conversant], false); {{default}}
If you want to record the name of the object that the player picked up, so you can check it in a later conversation, set the Script field to:

Code: Select all

Variable["PickedObject"] = Variable["Conversant"]
In the later conversation, you can check the value of Variable["PickedObject"].

Re: Collectible Objects with Conversation & Events

Posted: Wed Sep 02, 2020 2:42 pm
by bhavinsavajiyani
Hey!
Your help is much appreciated Tony!

But, when I implemented the instructions you provided, the object did not deactivate!
I received the following message in the console:
"Dialogue System: Sequencer: SetActive() command: subject 'Collectible' cannot be speaker or listener."

I had added one actor named "Collectible" to Dialogue System > Actors
And I selected that actor, in the Dialogue Actor's actor component.

Also, I just wanted to ensure whether I have to set up as many actors, as the number of collectible objects, and then on each object's Dialogue Actor's actor component, I select the respective name of collectible object?

Re: Collectible Objects with Conversation & Events

Posted: Wed Sep 02, 2020 2:46 pm
by Tony Li
Ah, that's right. The Dialogue System won't let you deactivate the speaker or listener. Can you disable its renderer and/or collider instead?

Code: Select all

SetEnabled(Renderer, false, [var=Conversant]); {{default}}

Re: Collectible Objects with Conversation & Events

Posted: Wed Sep 02, 2020 3:07 pm
by bhavinsavajiyani

Code: Select all

SetEnabled(Renderer, false, [var=Conversant]); {{default}}
The code does work.

But I have "Increment on Destroy" script, attached to every collectible object.
When use the "SetEnabled()" command, the object disappears due to disabling of renderers. But, the player's proximity selector's UI elements still show name of actor, when player is in radius & also, the object collection count does not increase, which won't update the Quest UI's text component which represents item count variable which I have set.

Is there any other way out?

Re: Collectible Objects with Conversation & Events

Posted: Wed Sep 02, 2020 3:41 pm
by Tony Li
You could also disable the collider and IncrementOnDestroy component:

Code: Select all

SetEnabled(Renderer, false, [var=Conversant]); 
SetEnabled(Collider, false, [var=Conversant]); 
SetEnabled(IncrementOnDestroy, false, [var=Conversant]); 
{{default}}
Or write a custom sequencer command to deactivate the GameObject. The SetActive() command has extra code that prevents it from deactivating the speaker or listener. You can leave that code out of your command.

Re: Collectible Objects with Conversation & Events

Posted: Wed Sep 02, 2020 4:21 pm
by bhavinsavajiyani
I had disabled the collider earlier, along with renderer.
Actually, I have a number variable which keeps track of number of items collected.
I have used that variable and set a condition in such a way, that the conversation with collectible object would only be triggered, when none of the collectible objects have been collected. And I have used “Increment on Destroy” intentionally, because that would save me the hassle of manually incrementing the count!
So, I suppose that wouldn’t work, if I just used the “SetEnabled()” command and disabled the renderers, colliders and Increment on Destroy components.
And Sorry, I have never set a custom sequencer command before.

If there is no other way round, apart from setting a custom sequencer command, what command should I set and how?
I have about 10-15 different collectible objects, and any one out of them could be collected. In that case, would there be any generic approach, where I could set such a command, which would only deactivate the object that was interacted with?

Keeping in mind the fact that I’m not a seasoned programmer & sometimes simple things get intimidating, apologies for the trouble.
Your help is much appreciated!

Re: Collectible Objects with Conversation & Events

Posted: Wed Sep 02, 2020 4:38 pm
by Tony Li
Here are two options that don't require programming:

1. Set the IncrementOnDestroy component Increment On: to Disable. Use the sequence in my reply above to disable the Renderer, Collider, and IncrementOnDestroy. When the sequence disables the IncrementOnDestroy component, the IncrementOnDestroy component will increment the variable.


2. Or remove the IncrementOnDestroy component. In the dialogue entry node's Script field, increment the variable.

Re: Collectible Objects with Conversation & Events

Posted: Wed Sep 02, 2020 5:56 pm
by bhavinsavajiyani
Thank You very much Tony!
That does resolve the roadblock!

But, it only worked once earlier, before you provided the last answer, when the renderer and collider components did actually get disabled!
After that, when I tried again, a couple of times, the conversation conditions did get satisfied, and the object count also got incremented, but the renderer and collider components did not disable!
Also, no warning or error messages showed up in the console!
Don't know what's causing the issue!

Re: Collectible Objects with Conversation & Events

Posted: Wed Sep 02, 2020 9:05 pm
by Tony Li
Are there two GameObjects with the same name? Maybe it disabled the Renderer, etc., on the wrong GameObject.

Temporarily set the Dialogue Manager's Other Settings > Debug Level to Info. This will log activity such as sequencer commands. If you examine the Console logs, it may give you a clue.