"Could not resolve C# type" error

I have a script that uses a custom enum. This custom enum is declared in C# and used as shown in the images. This has worked for weeks, but since I deleted a completely different variable, causing the script to recompile, I now get the error in the title of this post in the GeneratedComponents script, and the enum is not available to me in the inspector.

The images attached show the C# enum declaration, and its usage in the typescript script. Again, this has always worked for me, and has only given the error since removing an unrelated typescript variable that isnt being used. I have since added it back but the same issue occurs.


Original Post on Discord

by user 259070246382469121

Hello there – we have an experimental AI bot :robot: that might be able to help you with your question. Would you like to try this out?

How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.

Help requested: please wait a moment…

Here is what I found for you :brain: Discord

Hello Nostalgicbear, it looks like the Typescript to C# Component Compiler is having difficulty recognizing the custom enum that you’ve declared in C#. To resolve this, you can help the compiler by providing an annotation comment that specifies the correct type. You should place this annotation at the top of your Typescript class, providing the namespace and the type name of the enum. Here’s what you might add to your Typescript file:

//@type <Namespace>.<EnumName>

Replace <Namespace> with the namespace your enum is in, and <EnumName> with the name of your enum. If you want to make sure the Typescript class doesn’t generate a C# component, use the //@dont-generate-component annotation instead.

Please also make sure that the C# part of your project is correct and that there aren’t any other errors that might be causing this issue after you add the annotation. If the problem persists, you may also consider manually defining the required enum in C# outside of the auto-generated code regions marked by // NEEDLE_CODEGEN_START and // NEEDLE_CODEGEN_END in the GeneratedComponents script.

One more thing to check would be any changes in the build or compilation process that might have altered how the compiler treats your scripts. If the issue isn’t resolved with the above suggestions, examining recent changes in your development environment might provide some clues.

1 messages left GPT 4

Hi, the enum variable isnt declared in a editor script by any chance?

And could you let me know which component compiler is currently installed? You can find the version in the “ComponentGenerator” component

Hey Marcel, no its declared in a standard script although that standard C sharp script itself is named differently to the enum name, however this has never been a problem and this has been working for months until it recompiled today. THe standard C sharp script is shown in the image above and is called AnimatorEnum.

The component generator shows version 1.10.3

by user 259070246382469121

Yes the script/filename should not be a problem. We dont care about that.

Mmh latest is 1.11.1. which needle engine version are you using and can you send me a screenshot of your package.json (if it contains a specific version of the component compiler)

Needle engine version 3.27.4-pre

Here is a screenshot of the package.json

by user 259070246382469121

Just to add to the above, even creating a new C# script with the same enum and using that instead of the original results in the same “Could not resolve C# type” error

by user 259070246382469121

What the bot suggested above should also work with the @type

Or updating needle engine might

The “@type” approach gives me the error “‘AnimationChangePoint’: cannot derive from sealed type ‘AnimationOptions’”

AnimationChangePoint = The typescript script above
AnimationOptions = The enum

I dont see why AnimationChangePoint would be trying to derive from AnimationOptions behind the scenes as if it were a base class.

by user 259070246382469121

Did you add it to the class of your typescript script? Can you show? It should be above the enumfield in your typescript file

Otherwise you tell it to subclass your enum

For the issue above, I changed it to not be an enum. Adding the annotation didnt do anything, so I just changed the enum to be a string.

Today, in a similar manner to above, I edited a different script, simply adding a function to return a list, and it has caused changes that have messed up my project. I had a public list of a RacerEntry class in this script, and I had assigned these in the inspector. Today I added a function to return a list and it has caused the list in the inspector to disappear. This is the second time in a few days where editing an existing script in such a simple way has caused something to break on me. Can you please advice on what the hell I am doing wrong because I feel like I am banging my head against a wall every step of the way.

In the image: The custom RacerEntry class is shown, along with the list of racers. This is exactly how my script has always been. It had the public list in the inspector, and I could assign the various transform, sprite, and ints. Shown in the second image is the Racer.cs script that has not been modified in months.

Can someone please explain what I am doing wrong? Why does just adding a function to return a list cause this to happen? Is this not exactly how I am meant to do it? 1. Create a custom serializable .cs class. 2. Impletement the class in the .ts workspace. It has worked all along for months and now its broken.

by user 259070246382469121

Looks like RacerEntry is missing Unity’s [Serializable] attribute. I don’t think that issue is coming from Needle to be honest

I’ve seen a couple times that Unity cashes scripts incorrectly (e.g. has a compiled version of the script in memory even if your actual script looks different) and that “random changes” cause Unity to go “oops, need to recompile that script” – maybe you’ve hit that?

Ah wait sorry I mislooked

Which engine version are you on? I think there was an interim issue where some types were not correctly matched, but that has been fixed already