# Why my branch does not work?

**URL:** <https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [September 8, 2023, 10:26am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819 "2023-09-08T10:26:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![carmanfer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@carmanfer](https://forums.unrealengine.com/u/carmanfer)\
**Post date:** [September 8, 2023, 10:26am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/1 "2023-09-08T10:26:24Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/7/e/07e0a5e799a3846fc4907d9188e96cfb47d80c88.png)

When I pick up a sword, the boolean is right hand busy is set to true, but it does not prevent me from picking up another object. I can continue picking up stuff into my right hand socket for some reason (i.e. i can proceed to the switch node).

Why?

---

<div class="post-metadata">

**Author:** ![Shunitzo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shunitzo/32/1194547_2.png) [@Shunitzo](https://forums.unrealengine.com/u/Shunitzo)\
**Post date:** [September 8, 2023, 10:34am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/2 "2023-09-08T10:34:30Z")

</div>

Because you have check inside your intractable, not your character. That means every intractable have their own bool that has nothing to do with the right hand of your character.

---

<div class="post-metadata">

**Author:** ![carmanfer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@carmanfer](https://forums.unrealengine.com/u/carmanfer)\
**Post date:** [September 8, 2023, 10:36am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/3 "2023-09-08T10:36:44Z")

</div>

But it should have the same effect right? If the attach actor to component happens, then the bool is set to true, and then we should not be able to continue to the switch, and hence we could not execute another attach actor to component?

Well clearly my logic is wrong because it does not work. Could you specify how would I have to do it?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 8, 2023, 10:39am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/4 "2023-09-08T10:39:16Z")

</div>

Not only this, but I’d actually question the location of this script. We sure this whole thing should be in **every** item in the game rather than **only once** in the character that is supposed do the picking up thing? That’s what we’re doing, right? We are picking this item up?

> But it should have the same effect right?

No, you never ask the character whether their hands are full. You’re asking the item itself. And each item has its own bool. This bool should be in the char.

---

<div class="post-metadata">

**Author:** ![carmanfer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@carmanfer](https://forums.unrealengine.com/u/carmanfer)\
**Post date:** [September 8, 2023, 10:43am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/5 "2023-09-08T10:43:38Z")

</div>

This master blueprint serves as a parent to all the interactable items, so I do not see what is wrong with having the script here, could you explain the problem of this method?

Also, now I understand what you mean with each item has its bool, ofc they inherit from this.

Also, maybe having all this logic inherited by each child (item) is unnecessary code since a child only needs the code that applies to her type, not all the code for all types of items. I guess composition makes more sense? Although I still have to manage to make that work…

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 8, 2023, 10:52am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/6 "2023-09-08T10:52:04Z")

</div>

For me it’s a red flag because the item is allowed to modify the character. Would this make sense in your case:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/5/6/d56b318d3907b02e2c03aade1e4d58a7963e1255.png)

The player attempts to pick up the item 👆 , the item tells the player what it is 👇

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/3/2/9328d24268a1f1f7b8514cd2e8b11b77482f84e1.png)

* * *

If you wanted to use your method (it’s your game), perhaps it’d be enough to pipe in the player’s data into the interface message - you are already doing it with the mesh:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/f/4/4f427f8c14e932d269aa68a89927a0fad49f34ab.png)

So the items know if the player can handle them:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/c/0/1c00631e9ee47e53cf9af46c1586dcd45cca1f20.png)

But then you’d need to set the character’s `bool` somehow.

---

<div class="post-metadata">

**Author:** ![carmanfer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@carmanfer](https://forums.unrealengine.com/u/carmanfer)\
**Post date:** [September 8, 2023, 11:04am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/7 "2023-09-08T11:04:38Z")

</div>

It does make sense. Since the function that you have pick me up will be used in all the items that can be picked up, do you think it should be a component added to each item (child of actor) or should this be a function implemented in a master component from which each item inherits?

Also, do you think that my switch on type is the correct way to mount this system?

Right now the character BP looks like this:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/5/c/85c534ada4641d222c0009d46b9b3a460c9b47e2.png)

Line trace while holding “E”, if the hit actor implements BPI Interact then request info (the interface is in the previous screenshot in the master BP). The we get the info that sets the struct with variables name, type, actor ref.

Upon releasing E, execute the pick up logic (ignore the is weapon unsheathed branch). If the reference to the object is valid, depending on the type add the object to the array “current object” if there is not one already.

I know this is messy, maybe you know of a better way to do an interact system that allows for many types of interactables?

edit: this sytem prevents picking up two obects of the same type, but not other objects of other types that share same socket. I guess I could add a AND bool to the types of weapons that are supposed to share socket in the branches after the switch on type.

---

<div class="post-metadata">

**Author:** ![Shunitzo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shunitzo/32/1194547_2.png) [@Shunitzo](https://forums.unrealengine.com/u/Shunitzo)\
**Post date:** [September 8, 2023, 11:10am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/8 "2023-09-08T11:10:57Z")

</div>

I think your system creates unnecessary steps, that overcomplicates your code.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 8, 2023, 11:13am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/9 "2023-09-08T11:13:31Z")

</div>

> [@carmanfer](#):
>
> I know this is messy, maybe you know of a better way to do an interact system that allows for many types of interactables?

You already have a neat `enum` for weapon types ==\> use it in your map. This way you do not need to switch, and do not need to risk mistyping strings:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/1/1/d1176fb955e388ca4b95a82253bb5db772bfd78f.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 8, 2023, 11:31am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/10 "2023-09-08T11:31:12Z")

</div>

> [@Shunitzo](#):
>
> I think your system creates unnecessary steps, that overcomplicates your code.

Seconded. Things will be only getting more and more convoluted.

---

<div class="post-metadata">

**Author:** ![carmanfer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@carmanfer](https://forums.unrealengine.com/u/carmanfer)\
**Post date:** [September 8, 2023, 11:39am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/11 "2023-09-08T11:39:31Z")

</div>

I agree with both of you, but I’m having trouble ideating a method that allows me to carry out different logic upon interaction, for example pick up weapons, open doors, place things in inventory if they are miscellaneous. I’m trying the one you said before in your second answer.

Considering that each weapon will have stats, should I be using enums and switch by type? Or it does not matter for this interact logic and I should only differenciate the socket that it gets attached to (or inventory)?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 8, 2023, 11:58am UTC](https://forums.unrealengine.com/t/why-my-branch-does-not-work/1287819/12 "2023-09-08T11:58:53Z")

</div>

> [@carmanfer](#):
>
> a method that allows me to carry out different logic upon interaction

You’re using inheritance. You have a master item. You’re on the right track. Override the interface function for items that need to behave differently.

> for example pick up weapons, open doors, place things in inventory if they are miscellaneous.

- you have a master item which can dictate default behaviour:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/5/9/7599555d32d375abc9f54c374a5ba7a843fe0366.png)

- you have a vase that is pickable but breakable; it also can, optionally, respect default behaviour and add its own:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/9/1/b915f2bc1497b71a5fe376852ec293854cb551a0.png)

- and you have a door that is not pickable, but plays a timeline only it knows about:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/7/d/a7df5b6f864d77b9b673b53947efe1703ebc05a5.png)

The player just fires the same message at them:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/b/d/4bd72eafa54300542f1171fab90b43b91e7eb8d7.png)

The items choose how to respond to it.

* * *

Also, a long post that goes into lots of details:

> [@Why does this gate not work?](https://forums.unrealengine.com/t/why-does-this-gate-not-work/479135/14):
>
> And would I access that from the first person character, or the object? an interface has a bunch of generic functions that do nothing actors with this interface have access to those functions; think new, yet undetermined behaviours & results actors can interpret what each function does to determine the result when the player interacts with an actor, it calls those generic functions of the interface - and it is the actor’s job to do something with that call The player does not need to ident…
