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"

Object finder: cannot convert 'UStaticMesh ' to 'UObject '

The error in the output log:

 error C2664: 'void
 ConstructorHelpers::ValidateObject(UObject
 *,const FString &,const TCHAR *)': cannot convert argument 1 from
 'UStaticMesh *' to 'UObject *'
 Line 109 in ConstructorHelpers.h: ValidateObject( Object, PathName, ObjectToFind );

The code in the constructor:

     static ConstructorHelpers::FObjectFinder<UStaticMesh>meshAsset(TEXT("/Game/Meshes/SM_MinePickaxeB_01")); // <<< error for this line
 StaticMeshComp->SetStaticMesh(meshAsset.Object);

I also tried my own function but that one gave the exact same error:

 // cpp constructor call
 StaticMeshComp->SetStaticMesh(ULib::CreateObject<UStaticMesh>("/Game/Meshes/SM_MinePickaxeB_01"));
 
 // static function
 
     template <typename Type>
     static Type* CreateObject(FString Path)
     {
         Type* Temp = nullptr;
         Temp = ConstructorHelpers::FObjectFinderOptional<Type>(*Path).Get();
 
         #if WITH_EDITOR
           if (Temp == nullptr) { UE_LOG(LogTemp, Error, TEXT("%s"), *Path) }
         #endif
 
         return Temp;
     }

It compiled before but I added literally 1 line to the cpp file:

 WeaponAnimType = EWeaponAnimType::Pistol; // TODO: Use pickaxe animation.

and ever since I can't get it to compile anymore... Not even when I outcomment that newly added line. What am I doing wrong?

Product Version: UE 4.18
Tags:
more ▼

asked Nov 30 '17 at 06:59 AM in C++ Programming

avatar image

Napoleonite
562 82 98 144

avatar image Napoleonite Nov 30 '17 at 12:15 PM

So eventually I outcommented it all in a desperate way to get the project to compile and then this happened:

https://answers.unrealengine.com/questions/486502/projectnamehpch-is-not-a-valid-precompiled-header.html?childToView=730840#answer-730840

That's literally 3 compiler errors in a row for 1 (outcommented) line of code. That's really bad...

alt text

I cleaned the project AGAAAAAAAAAAAIN and now it compiles. Of course without any mesh assigned but hell, at least the project compiles. What is going on....

seriously.png (87.1 kB)
(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Apparently the compiler expects an UObject. UStaticMesh* is an object but... Pressing F12 on UStaticMesh* brings me to a forward declaration in Engine.h. So the compiler does not (yet) know that this in fact is an UObject.

Solution (yes it's very simple):

 #include "Engine/StaticMesh.h"

Of course the question still remains: Why did it compile prior to adding this nonsense line:

  WeaponAnimType = EWeaponAnimType::Pistol; // TODO: Use pickaxe animation.

And why does it also not compile anymore when I hit ctrl+z until it reverts back to the original state? It still does not compile even though the code is now EXACTLY THE SAME as when it used to compile. BUT when I use SourceControl to revert the exact same change, then it compiles. So even though I found the problem and solved it, there is something much more nasty going on somewhere (and I still suspect a UE4-related bug). If someone figures this out some day, please let me know!

more ▼

answered Nov 30 '17 at 06:50 PM

avatar image

Napoleonite
562 82 98 144

(comments are locked)
10|2000 characters needed characters left
Your answer
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