Download

C++ Cant' modify struct Component in details/viewport panel

Hey guys,

I’m trying to do something really simple, I have a struct with some component that I create in my constructor and attach it to the root. No problem so far, everything is created and moved in the origin of my Root. But When I go into my blueprint to move those component manually, I can’t access them.



USTRUCT(BlueprintType)
struct XROAD_API FXRoadVehicleSeat
{
    GENERATED_USTRUCT_BODY()

public:

    FXRoadVehicleSeat() {}

    FXRoadVehicleSeat(UBoxComponent* LocalDoorInteractionCollision,
        UArrowComponent* LocalExitVehicleArrow,
        EDoorPosition LocalDoorPosition,
        FName LocalSocketName,
        AXRoadPedestrian * LocalPedestrianOnTheSeat = NULL,
        bool bLocalIsDriverSeat = false)
    {
        DoorInteractionCollision = LocalDoorInteractionCollision;
        ExitVehicleArrow = LocalExitVehicleArrow;
        DoorPosition = LocalDoorPosition;
        SocketName = LocalSocketName;
        PedestrianOnTheSeat = LocalPedestrianOnTheSeat;
        bIsDriverSeat = bLocalIsDriverSeat;
    }

public:

    UPROPERTY(BlueprintReadWrite, VisibleAnywhere, meta = (AllowPrivateAccess = "true"), Category = "XROAD|Vehicle|Seats")
    UBoxComponent * DoorInteractionCollision;

    UPROPERTY(BlueprintReadWrite, VisibleAnywhere, meta = (AllowPrivateAccess = "true"), Category = "XROAD|Vehicle|Seats")
    UArrowComponent * ExitVehicleArrow;

    UPROPERTY(EditAnywhere, meta = (AllowPrivateAccess = "true"), Category = "XROAD|Vehicle|Seats")
    EDoorPosition DoorPosition;

    UPROPERTY(EditAnywhere, meta = (AllowPrivateAccess = "true"), Category = "XROAD|Vehicle|Seats")
    FName SocketName;

    UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "XROAD|Vehicle|Doors")
    AXRoadPedestrian * PedestrianOnTheSeat;

    UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "XROAD|Vehicle|Seats")
    bool bIsDriverSeat;
};

This is my stucture containing my two component I want to modify.



    UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "XROAD|Vehicle|Interaction")
    TArray<FXRoadVehicleSeat> VehicleSeats;

Here is my declaration of FXRoadVehicleSeat which is my structure containing my components.


    NumberOfSeats = 4;

    for (int i = 0; i < NumberOfSeats; ++i)
    {
        // Door Collision
        UBoxComponent * Collision = CreateDefaultSubobject<UBoxComponent>(FName(*FString(GETENUMSTRING("EDoorPosition", (EDoorPosition)i) + "_Collision")));
        Collision->SetupAttachment(RootComponent);

        // Exit Arrow for the pedestrian
        UArrowComponent * ExitVehicleArrow = CreateDefaultSubobject<UArrowComponent>(*FString("ExitArrow_" + FString::FromInt(i)));
        ExitVehicleArrow->SetupAttachment(Collision);

        VehicleSeats.Add(FXRoadVehicleSeat(Collision,
            ExitVehicleArrow,
            (EDoorPosition)i,
            FName(*(GETENUMSTRING("EDoorPosition", (EDoorPosition)i))),
            NULL));
    }


And finally my constructor where I initialize every Component.

Here is the result of this code. I still can’t access them, but if I’m putting them outside a struct It’s working as intended, I can modify them manually. I think I am missing something or it’s just not possible, I put VisibleAnywhere or EditAnywhere for my component and even BlueprintReadWrite but I still can’t have any control over them in my Viewport or details panel.

Any feedback is welcome! Thanks!

Try change USTRUCT(BlueprintType) to USTRUCT(Blueprintable)

change “visibleanywhere” to “editanywhere”

It does not seems to change anything, I did put USTRUCT(Blueprintable) as a property specifier and I still got the same result. Can you explain me a little more what this specifier do, I can’t seem to find any Documentation about it except some Korean site.


USTRUCT(Blueprintable)
struct XROAD_API FXRoadVehicleSeat
{
    GENERATED_BODY()

public:

    FXRoadVehicleSeat() {}

    FXRoadVehicleSeat(UBoxComponent* LocalDoorInteractionCollision,
        UArrowComponent* LocalExitVehicleArrow,
        EDoorPosition LocalDoorPosition,
        FName LocalSocketName,
        AXRoadPedestrian * LocalPedestrianOnTheSeat = NULL,
        bool bLocalIsDriverSeat = false)
    {
        DoorInteractionCollision = LocalDoorInteractionCollision;
        ExitVehicleArrow = LocalExitVehicleArrow;
        DoorPosition = LocalDoorPosition;
        SocketName = LocalSocketName;
        PedestrianOnTheSeat = LocalPedestrianOnTheSeat;
        bIsDriverSeat = bLocalIsDriverSeat;
    }

public:

    UPROPERTY(BlueprintReadWrite, VisibleAnywhere, meta = (AllowPrivateAccess = "true"), Category = "XROAD|Vehicle|Seats")
    UBoxComponent * DoorInteractionCollision;

    UPROPERTY(BlueprintReadWrite, VisibleAnywhere, meta = (AllowPrivateAccess = "true"), Category = "XROAD|Vehicle|Seats")
    UArrowComponent * ExitVehicleArrow;

    UPROPERTY(EditAnywhere, meta = (AllowPrivateAccess = "true"), Category = "XROAD|Vehicle|Seats")
    EDoorPosition DoorPosition;

    UPROPERTY(EditAnywhere, meta = (AllowPrivateAccess = "true"), Category = "XROAD|Vehicle|Seats")
    FName SocketName;

    UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "XROAD|Vehicle|Doors")
    AXRoadPedestrian * PedestrianOnTheSeat;

    UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "XROAD|Vehicle|Seats")
    bool bIsDriverSeat;
};
 


As I mentioned in my first post, I already tried this. Furthermore, As this post: EditAnywhere vs VisibleAnywhere - UE4 AnswerHub explain it, the best way to handle an UObject pointer is to put a VisibleAnywhere.

Thanks,

Kvyosh

BlueprintType means blueprints can use this struct. it will be visible for scripts. Blueprintable means blueprints can inherit from this object.

If you want components to be accessible like that, you have to make UProperties for each of them on the actor - having a struct inbetween isn’t going to work.

Ok thanks, I was expecting it to be like this. I really hope EPIC can make this possible in the future, It really help refactoring and add more visibility in my code but oh well guess we can’t have everything :slight_smile: .

One last question, Is it possible to have a TARRAY of my components in my actor and have them accessible in my blueprint? Like instead of declararing each component one by one on my actor like this:



    UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "XROAD|Vehicle|Effects")
    UParticleSystemComponent *VehicleSkidsParticleFrontLeft;

    UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "XROAD|Vehicle|Effects")
    UParticleSystemComponent *VehicleSkidsParticleFrontRight;

    UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "XROAD|Vehicle|Effects")
    UParticleSystemComponent *VehicleSkidsParticleRearLeft;

    UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "XROAD|Vehicle|Effects")
    UParticleSystemComponent *VehicleSkidsParticleRearRight


Having a TARRAY like this:


    UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "XROAD|Vehicle|Effects")
    TArray<UParticleSystemComponent*> VehicleSkidsParticle;

And still have access to them.

Thanks in advance,

Kvyosh

Haven’t tried that before. If it’s not working, probably not.

You might instead want to create an exposed TArray<UParticleSystem*> and then have a private TArray<UParticleSystemComponents*> that you create and register in a loop during OnConstruction.

Yeah in the end i’m doing everything through code, it wasn’t my ideal way of doing things because I wanted to have full access to those component in my viewport but I have no choice.

Thanks for the help guys.