CreateComponents vs GetComponents

Hello, I’m new to Unreal Engine, I just came from Unity, and I’m trying to create a simple game for learning things in Unreal, and I found it’s very difficult to understand sometimes.

I’m trying to Get Overlap events from my custom actor that is Plane object, it has its own collision that will block anything and box collision that I want it to be the trigger of my function.

  • the Object is already be put in scene, not be spawned in realtime.
  • the box component is already be acttached to the object, not be created in realtime.

and when I looked into the how to in internet, people always use CreateDefaultSubObject instead of using GetComponents which I usually use in Unity. And I’m very confused why people do it this way. Can anyone lighten up for me? and how should do it in the proper way? Thank you.

Get… would be to find out about things that are already there.

Add… ( and no doubt many other prefixes ) is used to make components.

The standard way to do this ( in blueprint anyway ) would be to just have a BP with the plane and a collision box in it.

You can then use ‘on begin overlap’ as the event.

The reason for CreateDefaultSubObject is to instantiate the component during the objects construction phase. It’s just an extra step to creating the component in code, without it components just a definition in the header file.

Unity is different in this aspect that it’s c# which doesn’t have the distinction of header files and cpp files.

In unreal you can use

GetComponentByClass or the plural form GetComponentsByClass

Yeah, I found people usually do that, but I want to get to basic code and then go to the blueprint after.

1 Like

Thank you, I will try this.