Faster Load time or error with codes?

Hi
How can i fully load my game faster, I followed the user Manual and still i have a problem with the in-game load of assets, for example i’ll load my game in the launcher and test it and one of the objects of the game to do is to have the character get swapped to another scene and load all the assets the are in it with eaz by collision, but instead the scene will freeze and like i said before i’ve optimize the textures, deleted the high render assets, and i even went in the setting and made the performance lower, and did everything i could to force the game get low and playable with fast reloading and fast performance in game. if anyone can i’ll add them to my project so we can get to the bottom of this situation

editor - PlayCanvas | HTML5 Game Engine
overwrite - PlayCanvas 3D HTML5 Game Engine

Hi @Kelvin_Riley2!

Your project is very complex. Can you please tell the exact steps to reproduce the problem? Also which scene, script, entities and assets are involved?

It might be an idea to reproduce the problem in a new project, using only necessary parts, to make it easier to find the cause.

1 Like

The particular scripts used with this is “ChangeSceneByCollision.js”
The assets or renders in it are everything in the project that needs to be involved with the next scene
The Scenes are the ones with the key word “ACT Num of act - TAKE Num of take

The exact steps that happen is for example the player having a collision event with an invisible radius that triggers the player to go to the next scene that will be activated in the scene.

code editor - PlayCanvas | HTML5 Game Engine

Are you sure? Below the first texture I checked. The resolution is very high and if you use a lot of them that can cause the loading times.

I would also use the latest API to change the scene, just to make sure everything is set up correctly.

this.app.scenes.changeScene('Some Scene Name');
1 Like

Actually no i didnt see that but thank you for showing and telling me !! , 4096x4096 is big resolution i shouldn’t have, im going to link you to the project because i’m not sure if it’s right, i need to go out and i’ll be back tonight but I’ll need help redoing the code

Im back and im wondering can i add you into the project to help me with the codes and problem?

If the code you use doesn’t give any problems, you don’t have to change it. First you need to optimize all textures. After that you can see if more optimization is needed.

1 Like

How can i optimize the textures ?

You need to resize the texture. I suggest a size of 512x512 or 1024x1024, based on the size of your model. You can do this with an online photo editor or similar software. Upload the new texture and delete the old texture. Please note that you will need to reassign the new texture to your material(s).

More tips and tricks for a better load time can be found on the page below.

https://developer.playcanvas.com/en/user-manual/optimization/load-time/

Okay i’m on that but what about the script problem with my scenes loading ?? like what’s a code I should use instead of the one i have for the “ChangeSceneByCollision.js”

var ChangeSceneByCollision = pc.createScript('ChangeSceneByCollision');

ChangeSceneByCollision.attributes.add("sceneName", {
    type: "string",
    default: "",
    title: "Scene Name to Load"
});

ChangeSceneByCollision.attributes.add("player", {
    type: "entity",
    title: "Player",
    description: "Select the Player entity"
});

// initialize code called once per entity
ChangeSceneByCollision.prototype.initialize = function () {
    this.entity.collision.on('triggerenter', this.onCollisionStart, this);
};

// update code called every frame
ChangeSceneByCollision.prototype.update = function (dt) {

};


ChangeSceneByCollision.prototype.onCollisionStart = function (entity) {
    if (entity.name == this.player.name) {
        var self = this;

        //entity.other.script.playerMovement.enabled = false;
        //var anim = entity.other.findByName("Model"); 
        //anim.script.playerAnimationHandler.enabled = false;
        this.app.keyboard.off(pc.EVENT_KEYDOWN, this.keyChange, this);
        this.app.keyboard.off(pc.EVENT_KEYUP, this.keyChange, this);
        //this.app.mouse.off("mousemove", this.onMouseMove, this);


        self.loadScene(self.sceneName);
    }

};

ChangeSceneByCollision.prototype.initStart = function (manager) {

    var oldHierarchy = this.app.root.findByName('Root');

    oldHierarchy.removeChild(manager);

    this.loadStart(this.startScene, function (newHierarchy) {
        newHierarchy.addChild(this.manager);

        oldHierarchy.destroy();

    }.bind(this));

};

// swap method called for script hot-reloading
// inherit your script state here
// GameOver.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/

What is the problem exactly?

When the player triggers the event like said in the code into the next scene it freezes and makes the game un-played towards the next event

I’m almost unable to test the project because of the load time. Your project is so big that it will be a lot of work to solve all the problems. Perhaps it is an idea to rebuild each scene in a new project and only start the next scene when the scene works without problems. Also, only use things you really need. For example, I see you have added high resolution textures to every slot of the material and I doubt if this is necessary and good for performance.

I don’t get the freezing, but I get some errors.

I will remake the project and try it again with remaking the scenes.

Question thought : Do you have any recommendations on how i can make the load time faster?

and also i’ve fixed that so if you have the time can you retry to scene because the script is updated

I already shared them.

Most important:

  • Smaller textures
  • Only necessary things
  • Remove unused assets
2 Likes