@Needle Engine Assistant
show me an example using @dont-generate-componentin typescript
by user 151660356224286721
@Needle Engine Assistant
show me an example using @dont-generate-componentin typescript
by user 151660356224286721
Certainly! The @dont-generate-component decorator in TypeScript is used to exclude a class from being generated as a component in the Needle Engine for Unity. Hereās an example of how you can use it:
import { Behaviour, dontGenerateComponent } from "@needle-tools/engine";
@dontGenerateComponent
export class HelperClass extends Behaviour {
// Class implementation here
}
In this example, the HelperClass will not be generated as a component in the Needle Engine for Unity due to the @dont-generate-component decorator. This could be useful in scenarios where you have helper classes or utility classes that you donāt want to be treated as components in the Needle Engineās code generation process.
2 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw
@Needle Engine Assistant
import { Piece,Piecetype } from ā./Pieceā;
export class Queen extends Piece
{
pieceType: Piecetype = Piecetype.Queen;
awake()
{
super.pieceType= this.pieceType;
}
}
but cs is not updated and shows
SourceFile
ImportDeclaration
ImportClause
NamedImports
ImportSpecifier
Identifier
ImportSpecifier
Identifier
StringLiteral
ClassDeclaration
Reading types file
Needle.Typescript.GeneratedComponents.Piece
Found class: Queen
NAMESPACE Needle.Typescript.GeneratedComponents
Queen inherits Needle.Typescript.GeneratedComponents.Piece
ExportKeyword
Identifier
HeritageClause
ExpressionWithTypeArguments
Identifier
PropertyDeclaration
Found variable pieceType: Piecetype = Piecetype.Queen;
Variable: pieceType
TypeReference: Piecetype
Piecetype
Child: TypeReference ā Piecetype
EMIT member: āPiecetypeā @pieceType Last type found: null
Identifier
TypeReference
Identifier
PropertyAccessExpression
Identifier
Identifier
MethodDeclaration
Identifier
Block
ExpressionStatement
BinaryExpression
PropertyAccessExpression
SuperKeyword
Identifier
FirstAssignment
PropertyAccessExpression
ThisKeyword
Identifier
Found codegen sections
Write to C:\UnityProjekt\KenSe\game\TestAR\Assets\Needle\Components.codegen/Queen.cs
EndOfFileToken
by user 151660356224286721
Here is what I found for you
Discord
The code and output youāve provided indicate that the TypeScript class Queen is attempting to set a property from its superclass Piece. The TypeScript code itself appears to be correct. However, the generated C# output is missing because youāve only shared the console output, not the generated code itself.
Based on what youāve shared, it looks like the TypeScript compiler recognizes the Queen class and identifies that it inherits from Piece with a property pieceType. However, without seeing the resulting Queen.cs file or the complete build log, itās difficult to provide specific advice on why the C# class may not have been updated.
Here are some steps to consider:
Piecetype enum is correctly defined and exported in your TypeScript codebase, and the TypeScript to Unity component compiler knows how to handle it.Queen.cs from being generated.Queen.cs and compare it to the intended TypeScript logic. If the property pieceType is not being set as expected, there might be an issue with how the compiler handles enum assignments or inheritance.Queen.cs file.If after taking these steps the issue remains, it may necessitate closer examination of both the TypeScript source and the C# output, alongside the Needle Engineās documentation on class and component generation.
thread_567y7ByPEJSt39JwcFVJgfKw
4 messages left GPT 4
thread_567y7ByPEJSt39JwcFVJgfKw
Thanks for your feedback!
@Needle Engine Assistant
import { Piece,Piecetype } from ā./Pieceā;
export class Rook extends Piece
{
pieceType: Piecetype = Piecetype.Rook;
awake()
{
super.pieceType= this.pieceType;
}
}
I am getting this message :
SourceFile
ImportDeclaration
ImportClause
NamedImports
ImportSpecifier
Identifier
ImportSpecifier
Identifier
StringLiteral
ClassDeclaration
Reading types file
Class type is unknown and will not generate a component: Rook
Piece.ts
import { Behaviour, getWorldPosition, serializable} from ā@needle-tools/engineā;
import { Object3D, Vector3 } from āthreeā;
import { GameManager } from āā¦/GameManagerā;
export enum Piecetype{
Default,
Pawn,
Knight,
Bishop,
Rook,
Queen,
King
}
export enum Color{
Black,
White
}
export class Piece extends Behaviour {
@serializable(Object3D)
public pieceTransform!: Object3D;
@serializable()
public pieceType: Piecetype = Piecetype.Default;
@serializable()
public color?: string;
CompareToOtherPiece(otherPiece : Piece): boolean
{
return this.pieceTransform === otherPiece.pieceTransform &&
this.pieceType === otherPiece.pieceType &&
this.color === otherPiece.color;
}
PlacePiece(targetTransform : Object3D)
{
const worldPos: Vector3 = getWorldPosition(targetTransform);
const loclConvertedPos: Vector3 = this.gameObject.parent!.parent!.worldToLocal(worldPos);
this.gameObject.position.set(loclConvertedPos.x,loclConvertedPos.y,loclConvertedPos.z) ;
}
GetAreaTransform()
{
GameManager.getInstance().movementManager!.GetPieceBoardArea(this);
}
// SearchForMovableArea() : BoardArea
// {
// return
// }
}
by user 151660356224286721
Here is what I found for you
Discord
Based on the code you provided, it appears that the Rook class is not being recognized as a component for generation. This can occur when the TypeScript to Unity component compiler is unable to infer the class type correctly for generation as a component.
Here are a few possible reasons this may be happening:
Piece class is properly exported and accessible within the same context that Rook is being used.Piecetype enum is correctly defined, imported, and used within the Rook class.Rook class as a component.To address this issue:
Piece class.Piecetype enum is correctly imported and the property pieceType is of the correct type within the Rook class.Rook class is configured and recognized as a component for generation.If the issue persists, consider reviewing the compilerās documentation or reaching out to the support channels for the TypeScript to Unity component compiler to further investigate this issue.
3 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw
@Needle Engine Assistant
what is the correct import export for enum in this case ?
by user 151660356224286721
In TypeScript, importing and exporting enums follows a similar pattern to that of other types. Hereās the correct way to import and export the Piecetype enum:
In Piece.ts:
export enum Piecetype{
Default,
Pawn,
Knight,
Bishop,
Rook,
Queen,
King
}
In the file where you want to use the Piecetype enum (e.g., Rook.ts):
import { Piecetype } from "./Piece";
This allows you to import the Piecetype enum into other TypeScript files so that it can be used as a type within those files. This is the typical approach for importing and using enums across multiple files in TypeScript.
2 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw
Thanks for your feedback!
@Needle Engine Assistant
Debug :
SourceFile
ImportDeclaration
ImportClause
NamedImports
ImportSpecifier
Identifier
ImportSpecifier
Identifier
ImportSpecifier
Identifier
StringLiteral
ImportDeclaration
ImportClause
NamedImports
ImportSpecifier
Identifier
ImportSpecifier
Identifier
StringLiteral
EnumDeclaration
ExportKeyword
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumMember
Identifier
EnumDeclaration
ExportKeyword
Identifier
EnumMember
Identifier
EnumMember
Identifier
ClassDeclaration
Found class: Piece
NAMESPACE Needle.Typescript.GeneratedComponents
Piece inherits UnityEngine.MonoBehaviour
ExportKeyword
Identifier
HeritageClause
ExpressionWithTypeArguments
Identifier
PropertyDeclaration
Found variable @serializable(Object3D)
public pieceTransform!: Object3D;
Variable: pieceTransform
TypeReference: Object3D
Child: TypeReference ā UnityEngine.GameObject
EMIT member: āUnityEngine.GameObjectā @pieceTransform Last type found: null
Decorator
CallExpression
Identifier
Identifier
PublicKeyword
Identifier
ExclamationToken
TypeReference
Identifier
PropertyDeclaration
Found variable @serializable()
public pieceType: Piecetype = Piecetype.Default;
Variable: pieceType
TypeReference: Piecetype
Reading types file
EMIT member: āPiecetypeā @pieceType Last type found: null
Why canāt is pieceType: Piecetype = Piecetype.Default commented out?
by user 151660356224286721
Here is what I found for you
Discord
It looks like the TypeScript to C# component compiler is having trouble parsing the @serializable decorator for the Piece class, specifically the pieceType: Piecetype = Piecetype.Default; line.
Based on this, I recommend the following steps to resolve the issue:
Piecetype enum: Ensure that the Piecetype enum is correctly defined and accessible at the time and place where Piece is being declared.@serializable decorators.By addressing these points, you may resolve the problem with parsing the @serializable decorator for the pieceType property. If you continue to encounter issues, it may be beneficial to consult the documentation for the TypeScript to Unity component compiler or seek support through their official channels for this particular issue.
1 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw
@Needle Engine Assistant
why is Piecetype not resolved in c#?
Piece.ts
import { Behaviour, getWorldPosition, serializable} from ā@needle-tools/engineā;
import { Object3D, Vector3 } from āthreeā;
export enum Piecetype{
Default,
Pawn,
Knight,
Bishop,
Rook,
Queen,
King
}
export enum Color{
Black,
White
}
export class Piece extends Behaviour {
@serializable(Object3D)
public pieceTransform!: Object3D;
@serializable()
public pieceType: Piecetype = Piecetype.Default;
@serializable()
public color?: string;
CompareToOtherPiece(otherPiece : Piece): boolean
{
return this.pieceTransform === otherPiece.pieceTransform &&
this.pieceType === otherPiece.pieceType &&
this.color === otherPiece.color;
}
PlacePiece(targetTransform : Object3D)
{
const worldPos: Vector3 = getWorldPosition(targetTransform);
const loclConvertedPos: Vector3 = this.gameObject.parent!.parent!.worldToLocal(worldPos);
this.gameObject.position.set(loclConvertedPos.x,loclConvertedPos.y,loclConvertedPos.z) ;
}
}
Piece.cs
// NEEDLE_CODEGEN_START
// auto generated code - do not edit directly
#pragma warning disable
namespace Needle.Typescript.GeneratedComponents
{
public partial class Piece : UnityEngine.MonoBehaviour
{
public UnityEngine.GameObject @pieceTransform;
// public Piecetype @pieceType; ā Could not resolve C# type
public string @color;
public void CompareToOtherPiece(object @otherPiece){}
public void PlacePiece(UnityEngine.GameObject @targetTransform){}
}
}
// NEEDLE_CODEGEN_END
public enum Piecetype
{
Default,
Pawn,
Knight,
Bishop,
Rook,
Queen,
King
}
public enum Color
{
Black,
White
}
by user 151660356224286721
Here is what I found for you
Discord
The reason Piecetype is not resolved in the generated C# code for Piece is that the compiler is not recognizing the enum during TypeScript to C# code generation.
This issue could occur due to differences in how TypeScript and C# handle enums, or it may be related to the specifics of how the Needle Engineās TypeScript to C# compiler interprets enums.
To address this, you can try the following:
Piecetype enum to ensure it has been appropriately generated and exported.By addressing these points, you may gain insights into why the Piecetype enum is not being resolved in the generated C# code, and identify the necessary steps to resolve the issue. If the problem persists, seeking support through official channels or forums specific to the Needle Engineās TypeScript to C# compiler could provide valuable assistance.
0 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw
Thanks for your feedback!
Dont generate component is added a the top of a class like this (as a comment) //@dont-generate-component
What i asked you to use is // @type YourNamespace.YourTypeName above a field.
I linked the docs in my post before. You should refer to the docs
thank you so much Marcel !
by user 151660356224286721