How to acess same variables in diferent classes?

I have 2 very similar playble characters [a) CH_human; b) CH_1stperson] they share the same variables and logaritms with some diferences that are not relevant for now (they are neither parent or child of each other) and I have this NPC that is programed to interact with the A)“CH_human”, but i want it to also interact with B)“CH_1stperson” in the same way.

Im currently accessing the A) variables through a cast:

Like I said before, that isBreathing (and many others) variable is common in both characters, and I wanted to know if there is a simple way to get those variables in characters of diferent classes, maybe by using tags but i dont quite knowh ow to do it or if its the correct way…

Normally you should make a “Master BP” that shares functionally within its children to effectively share and get all those Variables, Functions etc.

If you went for a Cast already - whenever it’s not the Player that interacts (the ‘human’ BP) it will go through Cast Failed - here you can specify the next Actor that should be affected by the code as well

You can nest as many as you wish but isn’t checking for “Player master” and “Enemy Master” better rather than adding 27366318 Enemies to the BP?

Because if you Cast to master - it will work for Children of this Class as well so you don’t have to worry for any new (same) Class Actor and don’t have to add it to the Nested Casts

1 Like

And just so you know - even if you place same structure in two different classes - those are two totally separate Actors and DO NOT share anything in particular, only main Class info

But if you need to share functionality between multiple similar Actors - make the First actor fully, call it Master -something- BP

Now from this you can create children that will contain same code and if you overwrite something in Child (f.ex. BeginPlay or Button Presses) it will affect this specific child only

So if you have a Master Weapon, it can have a Magazine as any other weapon but different amount of Max Bullets

It’s easier and faster to maintain Children Actors instead of separate actors, especially if those share same functionality (even partially)

1 Like

I didnt make a children of the human bp because this one is for some levels where the cameras are like cctv and are in the level not in the “CH_human” character bp, in other hand the “CH_1st person” has a camera of its own and extra coding for that camera that is not in the “CH_human” and also diferent movement inputs coding (because of orientation of the cameras) thats why i dindt wanted to make a child of the master , I tought that i couldnt make this input changes for example, I think i will try this: “If you went for a Cast already - whenever it’s not the Player that interacts (the ‘human’ BP) it will go through Cast Failed - here you can specify the next Actor that should be affected by the code as well” for this case that is only 2 diferent charaters it shouldnt be a big problem… thank you for the help :wink:

1 Like