GitHub Documentation Patreon donate button

"Types" of Undefined in Reflection.js error in Unity



  • Hey all,

    Just started using colyseus and loving it! Though, since I'm pretty new, this might be a user error, but I was fighting an error from Reflection.ts as a result of having a null schema and thought I'd share in case someone else runs into it. I wasn't accessing anything in the schema, just attempting to instantiate it. I've lost the exact error syntax, but it was along the line of "cannot access "types" of undefined from Reflection.js line 98." Looking at that bit of code, I guess the for loop needs to include a null check before running. I was able to resolve the issue by adding a dummy variable to the schema and regenerating it. It was literally just a string that I didn't access, but it was enough to validate the if/else checks in Reflection.js I suppose.

    Anyone else see this before? My guess is there's literally no reason for a null schema... unless you're a total noob who's butchering the example projects :).

    Relevant reflections logic:

    var buildType = function (currentType, schema) {
                for (var fieldName in schema) {
                    var field = new ReflectionField();
                    field.name = fieldName;
                    var fieldType = void 0;
                    if (typeof (schema[fieldName]) === "string") {
                        fieldType = schema[fieldName];
                    }
                    else {
                        var isSchema = typeof (schema[fieldName]) === "function";
                        var isArray = Array.isArray(schema[fieldName]);
                        var isMap = !isArray && schema[fieldName].map;
                        var childTypeSchema = void 0;
                        if (isSchema) {
                            fieldType = "ref";
                            childTypeSchema = schema[fieldName];
                        }
                        else if (isArray) {
                            fieldType = "array";
                            if (typeof (schema[fieldName][0]) === "string") {
                                fieldType += ":" + schema[fieldName][0]; // array:string
                            }
                            else {
                                childTypeSchema = schema[fieldName][0];
                            }
                        }
                        else if (isMap) {
                            fieldType = "map";
                            if (typeof (schema[fieldName].map) === "string") {
                                fieldType += ":" + schema[fieldName].map; // array:string
                            }
                            else {
                                childTypeSchema = schema[fieldName].map;
                            }
                        }
                        field.referencedType = (childTypeSchema)
                            ? childTypeSchema._typeid
                            : 255;
                    }
                    field.type = fieldType;
                    currentType.fields.push(field);
                }
                reflection.types.push(currentType);
            };
    

    Thanks!


 

GitHub Documentation Patreon donate button

© 2019 Endel Dreyer