Inherited shape component trouble

Hello everybody!

The problem is as follows: if you simply attach a shape component to the character, then everything will be ok, when you open the character blueprint, a component will be visible, where you can select the type of collision (sphere, box or capsule).

If you create an inherited class from the shape component, then when attaching to the character, compilation occurs normally, but when you open the character in the editor, the engine crashes with an error:

Here is the content of the 49th line in the ShapeComponent implementation:

I copied the functions and removed all checks in the functions, the problem with opening the character disappeared, the component appeared, but there was no choice of the collision type.

I don’t know basic c ++, and have only been learning for a few months the pluses in the context of the engine. Please help, what should I add so that I can select the type of collision and can configure it? (with explanations please).

Hey,

first of all you should launch engine from Visual studio 2019 when creating code.

You will get property view, callstack and much more.

Your code might work. But you are failing your own code.

Remove this check if you don’t know what does it do.

check() - Checks if condition in () is false if so it “crashes”

you have done check(false && other condition)

&& is boolean operator if first condition is false it skips next.

so you made check(false) and it always crashes

This is first line of your callstack.

As for the visual studio, i need to think about it. I just really like VSCode, it’s lightweight, fast, with good extensions. But this is secondary, essentially the question - in the 3rd screenshot you can see that I removed all checks, leaving only the return operators.

Use blueprints no need to use C++ if you don’t know what will it do.

Blueprint for beginning is completly fine.

I am not new to blueprints, I have more than 2 years of experience and I know what I want. I’m new to C ++, so the question is about C ++ implementation.

It has what you say but it’s like 1/10 of functionality you can get with VS2019.

To expose property you need UPROPERTY(EditAnywhere) above your property declaration.

Example:

UPROPERTY(EditAnywhere)
FVector Location;

First of I guess it’s not meant to be used like you want to use it.
It should be done by changing it on static mesh BP.

But if you realy want than you need to get StaticMesh.

I have no idea how is your actor set up so I will go generic not efficient way.

Assuming you want to learn not to get pure answers I will provide explanation with links.

**
https://forums.unrealengine.com/development-discussion/c-gameplay-programming/100884-c-getting-components-is-there-a-guide-on-the-different-ways-to-get-them

Get UStaticMeshComponent
**

TArray<UStaticMeshComponent> StaticComps;
YourActor->GetComponents<UStaticMeshComponent>(StaticComps);

Than (assuming you got exactly one component) we will take first instance of this component

UStaticMeshComponent* YourStaticMeshComponent = StaticComps[0];

When you have this as variable you can use one of following.

  1. Set profile collision SetCollisionProfileName(FName InCollisionProfileName, bool bUpdateOverlaps=true)

If you want something more advanced take a look at GetStaticMesh() method on UStaticMeshComponent.

Inside you have UBodySetup class. You can get it from UStaticMesh by accesing variable BodySetup.

UBodySetup has FBodyInstance. You can access it by variable DefaultInstance

It has all settings you need.

LIKE:

TEnumAsByte ObjectType;

TEnumAsByte CollisionEnabled;

SetResponseToChannel(ECollisionChannel Channel, ECollisionResponse NewResponse);

View FBodyInstance class for more.

PS: I would suggest using nullptr for pointer type instead of NULL.
PS2: If you get trouble doing that you can ask. Will answer in free time.

Thanks for the advice, I understand what you are talking about, but I have not grown to VS2019 yet, because I just do not know about many functions and how to use them, what they mean, and what they are for. This is another reason why WHILE I am using VSCode.

Apparently I poorly formulated the question, in view of the fact that I use a translator. But thanks anyway for the answer. I will try to describe the situation in more detail.
I have a standard character. I need to attach a shape component to the skeletal mesh socket. Why exactly the shape component - because, depending on the mesh, I will have to choose the collision shape, box or capsule. I also need to add my own functionality to the component, but there are no problems with that. That is why I am making a component inherited from the shape component to fill it with my own logic.

Attaching component to component in C++ is easy:

Creating component:

UYourClassHere* YourComponent = CreateDefaultSubobject<UYourClassHere>(this, TEXT("YourComponentName"));

Make root

RootComponent = YourComponent;

Attach to other component

ComponentChild->SetupAttachment(ComponentParent);

I’ve tried this as well. Try to do it yourself, but with the INHERITED class shape component. I think you will understand what the problem is! :slight_smile: