I know there are a lot of similar questions, but I didn’t find one specifically addressing this. Why would I (or what’s the difference between) set up an interface and then message the event, when it appears that I can just reference the actor and call its event without an interface at all?
if you promote it to a variable you will see it’s type is already the specific type,so you can directly call its functions.
sometimes if the variable is an “real actor”(not specific third person character),the case you won’t be able to call its functions,unless you cast,or use interface.
the main point to me,is storing an actual type variable is heavy sometimes. So make all reference variables actors.and then use interface to send messages . There are other benefits like decoupling or something,those words I’m not familiar with.perhaps others could have good explanations .
References. Functions like “GetActorOfClass”, Cast to, etc create hard references between actors. It means that when one actor is loaded to memory, another actor has to be loaded as well. For small project is ok, but generally it’s not a good practice.
Interfaces are great when you want objects to react differently to the same event. For example Interact. If you use interface logic could look like: Trace to get actor in front of the player, send “Interact” interface message, object does it’s logic (if it’s door they will open, if it’s lever it unlocks something, etc). Without interface you would need to cast that object to all classes individually (cast to door->open, cast to lever->unlock, cast to … etc).
P.S. GetActorOfClass / GetAllActorsOfClass is very heavy function. It loops through all actors from the level… so imagine how it will lower your fps count in bigger level if it’s used somewhere in Tick.
I can’t think of any other specific benefits when using soft references, they are used to consume less memory, so generally optimize the game (this is already big benefit as it for example speeds up loading times), even when you only open blueprint you need to load all other referenced blueprints, so editor also can work faster.
Ah and one more thing - this is totally fine to create hard references from other actors to main classes (like Game Mode, Controller, PlayerCharacter/Pawn). So for example if you want BP_Door to cast to player, it’s fine (as player will be loaded to memory all the time anyway), but you shouldn’t cast from BP_Player to the door.