Components

Is it possible in the blueprint of an actor component to get access without casting to a variable of the actor that belongs to? For example, you have the variable of life on a character and you have a component on that character and you want to access to the life in the bp of the component.

Yes, with an Interface.


  • an actor with a component, variable and implementing an interface function:

  • the interface function:

  • the component fetching it:

1 Like

Yeah, but if I want to make another interface that deal damage to the player the problem is the same. With that solution I can get the health but if I want to set a new health on the component (the result of the damage) I need to cast to thirdperson character, right?

You mean on the Character, not on the component, right? And no, you can use the same interface, just implement another function that sets the value. You can also use an event dispatcher, even easier.

Besides that, there’s no need - such mechanism already exists:


Yes, the intention is to control the health of the player through this component

Use another function in the interface, or call a dispatcher - much neater.

  • in the component:

  • in the player:


Note that the native damage system already supports damage processing:

Half the time people reinvent the wheel, which can be fun, I admit. However, considering that we simply can…

…and have Damage Type process damage, this opens up for a plethora of options without inventing new systems. Also, consider that, perhaps, the player should not own the Health variable - you have a health component, let it manage health…

Most importantly though, how you structure it has to make sense to you and be legible.


Also, finally:

There’s the often overlooked:

image

I will try it. Thank you so much!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.