So maybe I just need an update?
by user 151660356224286721
So maybe I just need an update?
by user 151660356224286721
yes - what i mentioned was added in 3.25
I see, thank you !
by user 151660356224286721
@Needle Engine Assistant
GetExistingPosition(): BoardArea {
const movementManager = GameManager.getInstance().movementManager;
if (movementManager && movementManager.BoardArea2x2Matrix) {
for (const column of movementManager.BoardArea2x2Matrix) {
for (const boardArea of column) {
if (boardArea.pieceInCurrentArea === this) {
console.log(boardArea.description);
return boardArea;
}
}
}
}
throw new Error("BoardArea not found for the current piece.");
}
public OnSelect()
{
console.log(āOnSelectā);
Piece.selected = this;
this.GetExistingPosition();
//calculate posible position
//show them in UI
}
my function name is correct. but it keeps showing me this error.
EventList method:
Could not find method onSelect on object PawnLight_1. Please rename onSelect to OnSelect?
Ę OnSelect() {
console.log(āOnSelectā);
_Piece.selected = this;
this.GetExistingPosition();
}
in script: Pawn {__context: undefined, __name: āPawnā, gameObject: Mesh, guid: ā5586818795571196987_8956883846352713136ā, sourceId: āassets/noMarker.glbā, ā¦}
by user 151660356224286721
Here is what I found for you Discord
It looks like there might be a case sensitivity issue with the function name. In javascript and, by extension, TypeScript used by Needle Engine, function names are case-sensitive. The error message suggests that the engine expects the function name to be OnSelect
(with uppercase āOā and āSā), while your function might be defined as onSelect
(with a lowercase āoā) in some places.
Letās make sure that the method name is consistent everywhere in your code, using the exact same casing as the engine expects. Hereās how you should define and refer to the function OnSelect
:
public OnSelect() {
console.log("OnSelect");
Piece.selected = this;
this.GetExistingPosition();
// calculate possible positions
// show them in UI
}
Call the method using the exact same case:
this.OnSelect();
Please ensure that wherever you are binding the OnSelect
function to an event or calling it, you use the exact same casing. If the issue persists after making this adjustment, you might need to review the component documentation or lifecycle methods to ensure it is hooked up properly in the Needle Engine context.
4 messages left GPT 4
thread_MWfJTlQt2uenguWenl6kRuUz
@Needle Engine Assistant
import { Behaviour, EventList, IPointerClickHandler, PointerEventData, serializable } from ā@needle-tools/engineā;
export class SyncedClick extends Behaviour implements IPointerClickHandler {
@serializable(EventList)
onClick!: EventList;
/* eslint-disable */
onPointerClick(_args: PointerEventData) {
console.log("CLICKED!");
this.context.connection.send("clicked/" + this.guid);
this.onClick?.invoke();
}
/* eslint-enable */
onEnable(): void {
this.context.connection.beginListen("clicked/" + this.guid, this.onRemoteClick);
}
onDisable(): void {
this.context.connection.stopListen("clicked/" + this.guid, this.onRemoteClick);
}
onRemoteClick = () => {
console.log("RECEIVED CLICK");
this.onClick?.invoke();
}}
I see āCLICKED!ā in debug Terminal, but this.onClick?.invoke is not executing.
by user 151660356224286721
Thinking
@Needle Engine Assistant
didnāt change a thing but my classes are not generated in c#
import { Behaviour, serializable} from ā@needle-tools/engineā;
import { MovementManager } from ā./MovementManagerā;
import {Piece} from ā./Piece/Pieceā
import { BoardArea } from ā./BoardAreaā;
export {BoardArea};
export {Piece};
export {MovementManager};
export class GameManager extends Behaviour
{
private static instance: GameManager;
public static getInstance(): GameManager {
if (!GameManager.instance) {
GameManager.instance = new GameManager();
}
return GameManager.instance;
}
@serializable (Behaviour)
movementManager?: MovementManager;
InitialPiecePlacement() {
if (this.movementManager && this.movementManager.BoardArea2x2Matrix) {
for (const column of this.movementManager.BoardArea2x2Matrix) {
for (const boardArea of column) {
const piece = boardArea.pieceInCurrentArea;
if (piece) {
piece.PlacePiece(boardArea.gameObject);
}
}
}
}
}
awake() {
if (this.movementManager) {
this.movementManager.InitBoardArea();
this.movementManager.BoardArea2x2Matrix = [];
this.movementManager.ConvertBoardArea();
}
else
{
console.error("Missing moveManager Reference");
}
this.InitialPiecePlacement();
}
}
by user 151660356224286721
Here is what I found for you Discord
To ensure the TypeScript to C# component compiler generates your classes correctly, you need to follow certain conventions and coding patterns that the Needle Engine for Unity recognizes. The code youāve provided seems to not follow some of these patterns which could prevent the compiler from generating C# classes appropriately.
Letās correct a few things to adhere to the expected formats and conventions:
@serializable
decorator is used correctly; it doesnāt need to reference Behaviour
in this context as itās for input serialization.getInstance()
method accordingly.After making these changes, letās verify the TypeScript code:
*thread_567y7ByPEJSt39JwcFVJgfKw*
typescript
import { Behaviour, serializable } from ā@needle-tools/engineā;
import { MovementManager } from ā./MovementManagerā;
import { Piece } from ā./Piece/Pieceā;
import { BoardArea } from ā./BoardAreaā;
export class GameManager extends Behaviour {
@serializable
movementManager?: MovementManager;
InitialPiecePlacement() {
if (this.movementManager && this.movementManager.BoardArea2x2Matrix) {
for (const column of this.movementManager.BoardArea2x2Matrix) {
for (const boardArea of column) {
const piece = boardArea.pieceInCurrentArea;
if (piece) {
piece.PlacePiece(boardArea.gameObject);
}
}
}
}
}
awake() {
if (this.movementManager) {
this.movementManager.InitBoardArea();
this.movementManager.BoardArea2x2Matrix = [];
this.movementManager.ConvertBoardArea();
} else {
console.error("Missing moveManager Reference");
}
this.InitialPiecePlacement();
}
}
*thread_567y7ByPEJSt39JwcFVJgfKw*
Evaluate the changes and test if the TypeScript compiler now generates the corresponding C# class. If you are still having issues, ensure your TypeScript files are located within the appropriate directory that the Needle Engine observes for compilation, as outlined in the Unity side of Needle Engineās documentation.
4 messages left GPT 4
thread_567y7ByPEJSt39JwcFVJgfKw
Thanks for your feedback!
@Needle Engine Assistant
GameManager.ts
import { Behaviour, serializable} from ā@needle-tools/engineā;
import { MovementManager } from ā./MovementManagerā;
import {Piece} from ā./Piece/Pieceā
import { BoardArea } from ā./BoardAreaā;
export {BoardArea};
export {Piece};
export {MovementManager};
export class GameManager extends Behaviour
{
@serializable (Behaviour)
movementManager?: MovementManager;
InitialPiecePlacement() {
if (this.movementManager && this.movementManager.BoardArea2x2Matrix) {
for (const column of this.movementManager.BoardArea2x2Matrix) {
for (const boardArea of column) {
const piece = boardArea.pieceInCurrentArea;
if (piece) {
piece.PlacePiece(boardArea.gameObject);
}
}
}
}
}
awake() {
if (this.movementManager) {
this.movementManager.InitBoardArea();
this.movementManager.BoardArea2x2Matrix = [];
this.movementManager.ConvertBoardArea();
}
else
{
console.error("Missing moveManager Reference");
}
this.InitialPiecePlacement();
}
}
generated GameManager.cs
// NEEDLE_CODEGEN_START
// auto generated code - do not edit directly
#pragma warning disable
namespace Needle.Typescript.GeneratedComponents
{
public partial class GameManager : UnityEngine.MonoBehaviour
{
// public MovementManager @movementManager; ā Could not resolve C# type
public void InitialPiecePlacement(){}
public void awake(){}
}
}
// NEEDLE_CODEGEN_END
by user 151660356224286721
Here is what I found for you Discord
It seems that the C# code is not being generated properly for the GameManager class. This could be due to the way the @serializable decorator has been used in the TypeScript code.
The issue lies with how the @serializable decorator is being used. It should not reference the Behaviour class within its parentheses for input serialization. Instead, it should directly annotate the movementManager property.
Letās modify the TypeScript code with this correction and test again for C# generation:
import { Behaviour, serializable } from "@needle-tools/engine";
import { MovementManager } from "./MovementManager";
import { Piece } from "./Piece/Piece";
import { BoardArea } from "./BoardArea";
export class GameManager extends Behaviour {
@serializable
movementManager?: MovementManager;
InitialPiecePlacement() {
if (this.movementManager && this.movementManager.BoardArea2x2Matrix) {
for (const column of this.movementManager.BoardArea2x2Matrix) {
for (const boardArea of column) {
const piece = boardArea.pieceInCurrentArea;
if (piece) {
piece.PlacePiece(boardArea.gameObject);
}
}
}
}
}
awake() {
if (this.movementManager) {
this.movementManager.InitBoardArea();
this.movementManager.BoardArea2x2Matrix = [];
this.movementManager.ConvertBoardArea();
} else {
console.error("Missing moveManager Reference");
}
this.InitialPiecePlacement();
}
}
thread_567y7ByPEJSt39JwcFVJgfKw
Then, retest to check if the C# class for the GameManager is generated correctly after making this change. If issues persist, please ensure that the TypeScript file is located in the correct directory for the Needle Engineās C# generation process to work properly.
3 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw
Thanks for your feedback!
@Needle Engine Assistant can there be another cause for that? I donāt think @serializable is the reason.
by user 151660356224286721
Here is what I found for you Discord
There could be a variety of reasons why the C# code generation is failing. Here are some potential causes:
Incorrect TypeScript Syntax: Ensure that the TypeScript code follows valid syntax and conventions. Any syntax errors or unsupported language features can lead to issues with the generation process.
File Location: Verify that the TypeScript file is located within the appropriate directory that the Needle Engine uses for C# generation. The file must be in the expected location for the Needle Engine to recognize and process it.
Project Configuration: Check the projectās configuration and settings for the Needle Engine. Ensure that the components and scripts are configured properly within the Needle Engineās environment or Unity project.
Correct Engine Version: Make sure that you are using the correct version of the Needle Engine for generating the C# code. If there are multiple versions, verify that you are working with the compatible version.
Other Dependencies: If the TypeScript file relies on other custom classes, ensure that these are also correctly configured and compatible with the Needle Engineās C# generation process.
I recommend addressing these aspects to troubleshoot the issue with the C# code generation. If after checking these points the issue persists, further investigation into the project and its setup may be necessary.
2 messages left GPT 3.5
thread_567y7ByPEJSt39JwcFVJgfKw