Cast Type Name Error

Hello.
New guy here, so new I still have my receipt.

I am receiving the following error
image

image

I am unsure on how to resolve this. I have tried other approaches such as CastChecked, which does remove the errors but causes an issue at runtime.

This error appears in a few helper functions within this class. The inherits from a base class that inherits from ACharacter.

I receive this error on all Cast operations in this class, PS is Player State in the below.


image

The error is only in this class and not others, which leads me to believe I may have inadvertently done something. It would build last night successfully, as it is formed now and I could play and test.
The last thing I can recall doing was migrating some source files to a new project folder and adjusting paths. Could this cause an issue with Cast in one class?

Silly question but I’d appreciate any guidance, thank you.

This is resolved, I learned quite a bit during this as well but end of the day it is a very funny mistake. I created a function for enhanced input binding named Cast … well that will cause a problem won’t it.

:rofl:

1 Like

Cast<T>(ObjectToCast) is a fancy wrapper around dynamic_cast<T>(ObjectToCast) as a member of the base types, and a bit of Unreal Reflection Magic.

for the most part migrating files around in your own solution should be fine, as long as you keep track you your #include "path/file" relative to the folder the current file is in, or if you are including something from a different [ModuleName]_API.
so if I have a .h in the root of Source/Public, but want to include something from DataTypes/ folder then I need to specify the DataTypes/ directory. the only time moving things around can cause big harm is when you are using source control.
most of these are cleaned up by just doing a “Ctrl+B” a couple times for UBT to clean things up, but just might take closing and re-opening the IDE

If you really think something funny is happening with moving things around but should be reserved for Linker errors. then:

  • do all your move actions in the IDE or in Explorer which ever you prefer
  • close your IDE
  • in the root directory of your project Delete: Binaries/, DirivedDataCache/, Intermediate/, .vs/, and the [ProjectName].sln
  • then right-click [projectName].uproject select “Generate Visual Studio project files”
  • open the newly created [ProjectName].sln, wait for the parse to finish, and do a “build without run” “Ctrl+B” if that passes, try to run your project “Ctrl+F5”

WARNING: this should only be reserved for things like Linker Errors on your project, or corrupted Modules from very bad crashes.

A good note for general things: if you are getting errors “red squiggles” under a line of code that you are pretty sure should work (maybe if you are just trying to figure out what the function does), just hover over the different parts of the code line to see arguments, comments, and so on. if the squiggle is under any flavor of GENERATED_BODY() and it is spelled correctly that is just Visual Studio not understanding Unreal engine and you can ignore that with a sigh and a head shake.
In the case of the error you provided 'Type': expected an expression instead of a type especially if you have a <T> argument to your function probably means the function is not a Template which most flavors of casting should be a Template. the only other type of issue this can be is where the Template Type T is not defined in the scope (forgot a #includebut these can sometimes present a little more cryptically sometimes even as an error in an std .h file :frowning: )

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.