Coming from Godot (and previously a little bit Unity) I am trying to understand the practices UE expects me to… practice.
I am trying to generalize my actors and to use class inheritance where I can.
Let’s say I have a bridge BP and a troll BP. Every bridge has a troll so I want to make the troll a component of the bridge but I want to keep separate BPs so I can also work with separate logic flows more easily.
Let’s say BP_Troll has a custom event StartFight. And I want to trigger it when the player approaches the bridge. Right now I am doing this:
I dragged the BP_Troll to BP_Bridge to create a Child Actor. In the event graph, I used Get Child Actor to get the actor of the Child Actor component and casted it to BP_Troll then triggered its StartFight event.
There are many ways of achieving the same result. Your approach with a child actor is one of them and it would work fine. I like child actors for the same reason as you stated: they help with keeping the logic separate and result in less spaghetti.
for math formulas you might take a look at the math expression node.
About the original question, there is many ways to solve the problem. I am not sure what implications there may be using a child actor, but here is another method:
you can spawn actor of class to make the troll, then just Set the spawned actor to a variable so that you have a reference to it.
But there may not necessarily be any good reason to couple the two actors together like this. If they can communicate via a blueprint interface, that could eliminate the need for the two actors to have to be coupled together.
Professionals can explain the details better than I can, but the basic problem is that if you have a lot of classes coupled together (i.e. operating from a hard reference to another class), that can make life difficult for you down the road as your code is sort of like a spider web that is impossible to untangle when you need to make changes.
Can you direct me to a documentation or a simple tutorial?
I’ve seen tutorials using interfaces for triggering doors by pressure sensors and stuff but in those examples, they had to put both of the blueprints to the scene and in one of them, they needed to assign the other actor to an exposed (to editor) variable. This seems more open to mistakes to me (not generally of course).
You see, it doesn’t matter what the A and B are with interfaces, that’s the point of them. It’s an ‘actor’ talking to another ‘actor’. So you just use an interface to communicate with the child. Not casting and fiddling with load of wires
In this case, you have a reference to the child actor, that’s all you need.