x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Adding StaticMesh

Hi,

I am new to game development and Unreal Engine 4. I am using version 4.7

I have created a StaticMeshComponent and kept that as a RootComponent. Also I have added StaticMeshObject inside the code instead of adding it in the Details Panel. But its not working when I loaded it in the editor.

.h file:

 UCLASS()
 class BPCPP2_API AMyActor1 : public AActor
 {
     GENERATED_BODY()
     
 public:    
     // Sets default values for this actor's properties
     AMyActor1();
 
     virtual void PostInitializeComponents() OVERRIDE;
 
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
     
     // Called every frame
     virtual void Tick( float DeltaSeconds ) override;
 
     TSubobjectPtr<UStaticMeshComponent> StaticMeshComponent;
 
     UStaticMesh * Chair1;
     
 };

.cpp file

 AMyActor1::AMyActor1()
 
 {
 
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
     StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticComponent"));
 
     static ConstructorHelpers::FObjectFinder<UStaticMesh> ChairMesh1(TEXT("Content'/Chairs_Chair1.uasset'"));
 
     RootComponent = StaticMeshComponent;
     FVector Location(0, 0, 0);
     StaticMeshComponent->Mobility = EComponentMobility::Static;
     StaticMeshComponent->SetStaticMesh(Chair1);
 
 
 }

Can somebody please check the code and help me to find the solution for this issue.

Thanks in advance!

Product Version: Not Selected
Tags:
more ▼

asked Mar 19 '15 at 01:41 PM in C++ Programming

avatar image

purmo037
30 10 13 20

avatar image MickD777 Mar 19 '15 at 03:20 PM

What is Chair1 ? Your code declares the mesh variables as ChairMesh1, you should do

 StaticMeshComponent->SetStaticMesh(ChairMesh1.Object);
 //instead of
 StaticMeshComponent->SetStaticMesh(Chair1);
avatar image purmo037 Mar 19 '15 at 03:23 PM

Sorry I have changed that already. Can you check it?

 AMyActor1::AMyActor1()
 
 {
 
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
     StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticComponent"));
 
     static ConstructorHelpers::FObjectFinder<UStaticMesh> ChairMesh1(TEXT("Content'/Chairs_Chair1.uasset'"));
 
     RootComponent = StaticMeshComponent;
     FVector offset;
     StaticMeshComponent->Mobility = EComponentMobility::Static;
     StaticMeshComponent->SetStaticMesh(ChairMesh1.Object);
     offset = FVector(0.0, 0.0, 0.0);
 }

But still, I cannot see that Mesh is changing in the Details Panel.

avatar image MickD777 Mar 19 '15 at 03:43 PM

Your path is probably not valid, to get the proper path copy it from the editor, by selecting the asset and doing Ctrl+C. It should look something like this :

 "StaticMesh'/Game/Props/Cart/CartA.CartA'"

And btw, it's pretty obvious from your 2 post that you do not understand what you are doing, for example FVector offset; offset = FVector(0.0, 0.0, 0.0);

does absolutely nothing. This is really basic stuff, you should do some tutorial on Unreal 4 or C++ programming in general.

Here is a good link : https://www.youtube.com/playlist?list=PLZlv_N0_O1gaCL2XjKluO7N2Pmmw9pvhE

avatar image purmo037 Mar 19 '15 at 03:58 PM

No. Actually, I am selecting the object from the imported fbx file which I have kept it under content folder in Content Browser in the editor. I think its in /Game folder. I will try and let you know.

Actually I have changed that location as Gleb explained. I have already seen more tutorials for Blueprints but just I am entering into C++. Anyways thanks for sending the link. I will look for C++ tutorials.

avatar image mirsabayu Mar 19 '15 at 04:07 PM

Yah. But the link is likely to be like what michael Dube said. Just right click on your imported fbx and you'll see some words like reference viewer or something like that. After you click that. Paste the link to your object finder( that would be the link to your imported fbx.

avatar image purmo037 Mar 19 '15 at 04:12 PM

Thank you all so much for the help. I have tried with what you said and it shows the path "/Game/Chair1". It worked.

avatar image mirsabayu Mar 19 '15 at 04:20 PM

Yup. Sorry i am not in front of ue right now, so i can't check it by myself right now. But it would be like that. And if iam not forget. The idenyifier should automatically included (the StaticMesh). But your link shouldbe ok. ("StaticMesh'/Game/Chairs_Chair1"). Just try hehehe

avatar image purmo037 Mar 19 '15 at 04:24 PM

Yes of course you are right. Sorry to mention that in above. Thank you so much.

avatar image mirsabayu Mar 19 '15 at 04:26 PM

You're welcome. :) jejeje

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question