Announcement

Collapse
No announcement yet.

Using a BP wrapper to specify a static mesh from the content browser?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Using a BP wrapper to specify a static mesh from the content browser?

    I have a multi-wheeled vehicle I'm trying to code in c++. The idea is to have the meaty parts coded in c++ and use a BP wrapper to specify the static mesh components that make up the vehicle. Right now, I can specify the main chassis static mesh component just fine. The tricky part is the chassis can a variable number of wheels. What needs to happen is for the BP to accept a drag/drop from the content browser which allows the wheel's static mesh to be selected and passed to the c++ parent of the BP. The c++ code will then add the wheels as subcomponents to the chassis as needed when the actor is spawned. I have this declaration in the header file:

    UPROPERTY(VisibleDefaultsOnly, Category = MyVehicle)
    UStaticMesh* RoadWheel;

    However, the editor rejects attempts to drag a static mesh from the content browser into the BP for this variable. (Entry box turns red.)

    I know the usual way is to hard code the model. For example:

    static ConstructorHelpers::FObjectFinder<UStaticMesh> SomeMesh(TEXT("StaticMesh'/Game/Models/TheMesh.TheMesh'"));

    But I'd like to avoid that to allow some flexibility. What's the trick to do this?

    #2
    Have you tried "EditAnywhere, BlueprintReadWrite" ?

    HTH
    Never say Never, Because Never comes too soon. - ryan20fun

    Frames Per Second is NOT a proper performance metric, You should use frame time. You can read this or this as to why.
    (Profiling) Tools: RenderDoc (UE4 Plugin), NVIDIA nSight, AMD GPU PerfStudio, CodeXL
    Good articles/Series: A trip through the Graphics Pipeline 2011

    Comment


      #3
      Something like this? I didnt try the code, but it should work.

      UPROPERTY(VisibleDefaultOnly, BlueprintReadOnly, Category = Pickup)
      TSubobjectOtr(UStaticMeshComponent> PickupMesh;


      7.40 onwards.

      Comment


        #4
        Unfortunately, TSubobjectPtr seems to be deprecated --

        EMIT_DEPRECATED_WARNING_MESSAGE("TSubobjectPtr is deprecated and should no longer be used. Please use pointers instead.")

        I went back to using pointers and it compiles and runs. But it's not right ...

        // doesn't work
        UPROPERTY(VisibleDefaultsOnly, Category = MyVehicle)
        UStaticMesh* RoadWheel;

        // this works, but not what I want
        UPROPERTY(VisibleDefaultsOnly, Category = MyVehicle)
        UStaticMeshComponent* RoadWheel;


        I just need the name of the static mesh passed from the BP to the c++ rather than having the BP create an instance of a static mesh component. The code will create n-number of components from there on its own.
        Last edited by Whammy; 05-13-2016, 10:16 AM.

        Comment


          #5
          Sorry for recommending the wrong stuff. Should have done some research before then. I did some testing and the following is what i came up with.

          With C++ parent class of character (or actor class)

          // character.h
          UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
          UStaticMeshComponent * ThisMesh;

          // character.cpp constructor
          ThisMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("WhateverMesh"));
          ThisMesh->AttachParent = RootComponent;

          The above code can only set the mesh in the world detail panel (BP Character(Child) ... ThisMesh), i didnt manage to find a proper UProperty settings that allows setting of mesh in the BP editor. You might have to dig around for that settings if you need that. Hope this is what you need for your project.

          Comment


            #6
            If you can get the static meshes path you could add a mesh property to set the mesh and then load/create that from disk as many times as needed.
            Never say Never, Because Never comes too soon. - ryan20fun

            Frames Per Second is NOT a proper performance metric, You should use frame time. You can read this or this as to why.
            (Profiling) Tools: RenderDoc (UE4 Plugin), NVIDIA nSight, AMD GPU PerfStudio, CodeXL
            Good articles/Series: A trip through the Graphics Pipeline 2011

            Comment

            Working...
            X