Jump to content

Component::Load being called extra time and somehow field value in load being copied to next components


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

I'm not sure if it would be same for new objects with same component but in this case i made a prefab and copied it couple times

In Load() i assign a pointer if it was not yet, but it is with first pointer in next component instances.

I think something was changed in Ultra not too long time ago because i noticed this issue only recently in my game

Expected:

3 assigns in 3 objects and 3 different values in result check in main.

But have atm 1 assign due issue above and as result getting same value from same pointer:

image.png.74234768f68721b8d31c38a4d432d849.png

Example with prefab, map, main and component

CompLoad&PointerIssue.zip

Link to comment
Share on other sites

Okay, so here is what is happening:

The first time LoadPrefab is called in the scene load routine, the prefab file is loaded, and the Load method is run. The prefab stores the loaded entity in a NULL world, and then makes an instance of it and returns that instance. Every time LoadPrefab is called after that, and it detects the path is the same as the first call, another instance is of the prefab entity is returned.

At the end of the LoadScene routine, each component in each entity in the scene has its Load method called.

So three entities coming from one prefab means it is called once when the prefab is loaded, and then once for each entity in the scene.

Perhaps the Load method should be skipped for prefabs in the scene, because that data is all supposed to come from the prefab. In that case, the Load method would be called once, and the Copy method would be called three times.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

4 hours ago, Josh said:

Perhaps the Load method should be skipped for prefabs in the scene, because that data is all supposed to come from the prefab.

What will happen if these entities will be saved with Map::Save for saving game state?

Also second thing is that i create another class instance that tied to specific component instance (ai for unit in this case). I do it in Load to restore its state from Editor or save file. And this component member have a weak_ptr to component instance.

In some cases Load results may depends on entity position and rotation (not sure if it's a case in my game atm).

Probably it would be better not to skip Load(). I will try to handle my case manually in Copy(), even tho i have many unit based classes and calling parent class Copy is not an option because it seems to return Parent class from child *this :unsure:

Link to comment
Share on other sites

We will discuss this in tomorrow's meeting. I don't want to make any major changes to this until after my talk with Khronos on Monday.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

On 9/6/2024 at 8:38 PM, Josh said:

We will discuss this in tomorrow's meeting.

Most likely i will not attend it because it's a bit too late for me, but my position atm is not do Load() for prefab and do it only for its instances to avoid unintended behavior for game devs.

  • Thanks 1
Link to comment
Share on other sites

We did not get to it in the meeting, but my basic idea is this:

Currently, LoadPrefab first loads a copy of the scene into the NULL world and stores it, then returns an instance of the root entity. Any time the same prefab is loaded again, a new instance of the root entity is returned. This is why the extra call to Load is happening, and why the Load method must be able to handle the situation where the world is NULL. (It technically should anyways, but I can understand if people skip that.) I could probably disable this behavior without much trouble.

The other issue is that Entity::Instantiate copies flowgraph connections to the original entity. There is no way for Instantiate to know a flowgraph connection target is also being copied. This is why prefabs currently cannot store their own internal flowgraphic.

My idea is to make LoadPrefab load the JSON and binary data, and then run the scene load routine each time the same prefab is loaded. This would solve both problems easily.

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

My scene that contains a prefab does not have this problem. Can you provide instructions on how to make this error occur in your project?

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...