So I'm using unreal engine 5. I have a PlayerCharacter C++ Class called…
- User
So I'm using unreal engine 5. I have a PlayerCharacter C++ Class called NovaPlayerCharacter. Inside my header file, I have added this:
public: ANovaPlayerCharacter();
UPROPERTY(BlueprintReadWrite, Category = "Interaction") FName InteractionTraceStartSocket; UPROPERTY(BlueprintReadWrite, Category = "Interaction") float InteractionRange;Inside the .cpp file I have added these default values:
InteractionTraceStartSocket = FName("Head"); InteractionRange = 280.f;Everything works fine, however in my child blueprint, those variables aren't showing up in the class defaults.
When I change the lines to:
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Interaction") FName InteractionTraceStartSocket; UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Interaction") float InteractionRange;for example, the variables show up in the Class Default settings inside the child blueprint
- Assistant
It seems that the issue you are facing is related to the visibility specifiers of the blueprint properties. By default, when using
BlueprintReadWritewithout any visibility specifier, the properties are only accessible in Blueprints but not visible in the class defaults.To make the properties visible in the class defaults of the child blueprint, you need to add the
VisibleAnywherespecifier along withBlueprintReadWrite.So, your updated code should look like this:
public: ANovaPlayerCharacter(); UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Interaction") FName InteractionTraceStartSocket; UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Interaction") float InteractionRange;By adding
VisibleAnywhere, the properties should now appear in the class defaults of the child blueprint in Unreal Engine 5. - User
They do, however when I add :
UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = “Interaction”) FName InteractionTraceStartSocket; UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = “Interaction”) float InteractionRange;in the blueprints Class Default settings, the variables are greyed out and I can't edit them
- Assistant
If the variables are grayed out in the Class Default settings of the child blueprint, it means that they are marked as "const" or "const ref" in the C++ code. By default, when a property is marked as const in C++, it becomes read-only in Blueprints, hence you cannot edit it in the Class Default settings.
To make the variables editable in Blueprints, you need to remove the const specifier from the C++ code. Your updated code should look like this:
public: ANovaPlayerCharacter(); UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Interaction") FName InteractionTraceStartSocket; UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Interaction") float InteractionRange;After removing the const specifier, you should be able to edit the variables in the Class Default settings of the child blueprint.
- User
Okay, I created a custom Trace Channel called "Interactable"
Inside my ProjectNova.h file I want to define the trace channel as ECC_Interactable. I have added the following to my header file:
UENUM(BlueprintType) enum class ECustomCollisionChannel : uint8 { ECC_Interactable UMETA(DisplayName = "Interactable") // Add more custom collision channels here if needed };
- Assistant
Your code snippet is almost correct for defining a custom trace channel in Unreal Engine using an enumeration. However, there is a small syntax error in your code. To fix it, you need to add a comma after
ECC_Interactable. Here's the corrected code:UENUM(BlueprintType) enum class ECustomCollisionChannel : uint8 { ECC_Interactable UMETA(DisplayName = "Interactable"), // Add more custom collision channels here if needed };With this code, you have defined a custom collision channel named
ECC_Interactablein yourECustomCollisionChannelenumeration. You can now use this custom trace channel in your Unreal Engine project. - User
This line
GetMesh()->SetCollisionResponseToChannel(ECC_Interactable, ECR_Block)is giving me the error
Severity Code Description Project File Line Suppression State Error (active) E0020 identifier "ECC_Interactable" is undefined ProjectNova C:\Users\44793\Desktop\Unreal Engine Files\Unreal Engine 5.3\ProjectNova\Source\ProjectNova\Private\Character\NovaEnemyCharacter.cpp 9
- Assistant
The error message indicates that the identifier "ECC_Interactable" is not recognized in the given context. This usually occurs when the necessary header file is not included or the custom enumeration is not accessible.
To resolve this issue, ensure that you have included the header file where the custom enumeration
ECustomCollisionChannelis defined. In this case, it seems that the header file whereECustomCollisionChannelis defined is missing from yourNovaEnemyCharacter.cppfile.Make sure you include the appropriate header file at the top of
NovaEnemyCharacter.cppfile, like this:#include "YourCustomHeaderFileName.h" // Replace with the actual header file name containing ECustomCollisionChannelAlso, ensure that the custom enumeration is accessible/imported in the
NovaEnemyCharacter.cppfile. Double-check that you have included the correct header file and that it is properly set up.By including the correct header file and ensuring the custom enumeration is accessible, the identifier "ECC_Interactable" should be recognized in the given context without any errors.
- User
How do I define the variable?
- Assistant
To define a variable using the custom collision channel
ECC_Interactable, you can declare a variable of typeTEnumAsByte<ECustomCollisionChannel>. Here's an example:TEnumAsByte<ECustomCollisionChannel> MyCustomCollisionChannel = ECustomCollisionChannel::ECC_Interactable;In this example,
MyCustomCollisionChannelis a variable of typeTEnumAsByte<ECustomCollisionChannel>, and it is assigned the valueECC_Interactable.You can then make use of this custom collision channel variable in your code according to your requirements. For example, to set the collision response of a mesh component to
ECC_Interactable, you can do something like this:GetMesh()->SetCollisionResponseToChannel(MyCustomCollisionChannel.GetValue(), ECR_Block);Make sure to replace
MyCustomCollisionChannelwith the actual variable name you are using in your code.By defining and using the variable in this way, you can work with the custom collision channel
ECC_Interactablein your Unreal Engine C++ code. - User
Okay, for the CustomCollisionChannel what do I need to include in the header?
- Assistant
To include the custom collision channel
ECustomCollisionChannelin your header file, you need to add the following line:#include "YourCustomHeaderFileName.h" // Replace with the actual header file name where ECustomCollisionChannel is definedIn the line above, you should replace "YourCustomHeaderFileName.h" with the actual header file name where you have defined the
ECustomCollisionChannelenumeration.For example, if you have defined the
ECustomCollisionChannelenum in a header file called "CustomCollisionChannels.h", you would include it as follows:#include "CustomCollisionChannels.h"By including the appropriate header file, you make the
ECustomCollisionChannelenum visible and accessible in your current header file, allowing you to use it to define and work with variables of that type. - User
I'm trying to define
TEnumAsByte Interactable = ECustomCollisionChannel::ECC_Interactable;
inside my main project header file (ProjectNova.h)
However I'm getting the error
Severity Code Description Project File Line Suppression State Error (active) E0020 identifier "ECustomCollisionChannel" is undefined ProjectNova C:\Users\44793\Desktop\Unreal Engine Files\Unreal Engine 5.3\ProjectNova\Source\ProjectNova\ProjectNova.h 7
- Assistant
Based on the error message you provided, it seems that the compiler cannot find the definition of the
ECustomCollisionChannelenum in yourProjectNova.hfile.To resolve this issue, you need to make sure that the
#includedirective for the header file whereECustomCollisionChannelis defined is present at the top of yourProjectNova.hfile.For example, if the
ECustomCollisionChannelenum is defined in a header file called "CustomCollisionChannels.h", you would include it in yourProjectNova.hfile like this:#include "CustomCollisionChannels.h" // Replace "CustomCollisionChannels.h" with the actual header file nameMake sure to replace
"CustomCollisionChannels.h"with the actual header file name that contains the definition ofECustomCollisionChannel.By including the correct header file, the compiler will be able to find the definition of
ECustomCollisionChannel, and you should no longer encounter the "identifier is undefined" error. - User
Does this:
#define ECC_Interactable ECC_GameTraceChannel1
allow me to call ECC_Interactable to get ECC_GameTraceChannel1
- Assistant
Yes, the line
#define ECC_Interactable ECC_GameTraceChannel1allows you to use the symbolECC_Interactableas an alias forECC_GameTraceChannel1.In Unreal Engine,
ECC_GameTraceChannel1is a predefined trace channel value, and by definingECC_InteractableasECC_GameTraceChannel1using the#definedirective, you create an alias for the original value.By doing so, you can use
ECC_Interactableinstead ofECC_GameTraceChannel1in your code, and it will be treated as the same value.For example, with the line
#define ECC_Interactable ECC_GameTraceChannel1in place, you can useECC_Interactablein a function like this:void MyFunction() { // Using ECC_Interactable as an alias for ECC_GameTraceChannel1 ECollisionChannel MyCollisionChannel = ECC_Interactable; // Rest of your code... }Note that the
#definedirective is a preprocessor directive, and it performs a simple text substitution before the compilation process. - User
Great, so now I'm trying to use this inside an EnemyCharacter base class
GetMesh()->SetCollisionResponseToChannel(ECC_Interatable, ECR_Block);but it isn't changing my blueprints to block the Interactable Trace Channel
- Assistant
It seems there is a typo in your code. In this line:
GetMesh()->SetCollisionResponseToChannel(ECC_Interatable, ECR_Block);The enum
ECC_Interatableappears to have a typo. It should beECC_Interactable, matching the custom collision channel you defined earlier. So, the corrected line of code should be:GetMesh()->SetCollisionResponseToChannel(ECC_Interactable, ECR_Block);With this correction, the
SetCollisionResponseToChannelfunction should work as expected and set the collision response to block theECC_Interactabletrace channel for theMeshcomponent.Please update your code with this correction, and it should properly block the
ECC_Interactabletrace channel in your blueprints. - User
If I created a Custom Trace channel in the project settings, would it be using ECC_GameTraceChannel1? or the ECC_EngineTraceChannel1?
- Assistant
If you create a custom trace channel in the Project Settings of Unreal Engine, it will not be using either
ECC_GameTraceChannel1orECC_EngineTraceChannel1by default.By creating a custom trace channel, you define your own unique collision channel that can be used for traces and collision handling within your project. When creating a custom trace channel, you can specify its name, response, and visibility settings based on your project requirements.
The
ECC_GameTraceChannel1andECC_EngineTraceChannel1are predefined trace channel values provided by Unreal Engine, but they are separate from any custom trace channels you create in the Project Settings. Each custom trace channel that you create will have its own unique identifier and collision settings.To use your custom trace channel in code, you would typically refer to it by its specified name, not by the predefined trace channel values like . You can access the custom trace channel by its name and set the collision response accordingly using the function.