Upbge: A big problem with the Python Components initialization

Created on 27 Jul 2018  Â·  12Comments  Â·  Source: UPBGE/upbge

I'm creating my first game using exclusively python components and I discovered a small problem with their architecture...
If you imediatelly call a function that belongs into a component (from the start function of other component), this function may require a variable that was initialized on the start function of this component. But since you called this function imediactly, these variable don't exist yet.

I made a small .blendfile to show the problem:
http://pasteall.org/blend/index.php?id=50022

How to fix this?

Well, I'm thinking a lot about a solution to this problem, but I guess there is not a easy way to do this... but maybe a workaround could serve:
Instead of just one start function, maybe creating two start functions: one to initialize data and another to "start things" (like calling functions or everything that is not initialize data).

Edit: Another problem

In my game, I made some components that where used in various objects in different scenes, like the button component. During the development process, I had to make some changes on these components (like add or change the arguments). And the big problem is: I had to find every single button in the game to press the update button on each component. This was kinda painful.

What about an auto update? Like everytime the user opens the blender window (in case of an external IDE), or everytime the users changes the script inside blender (this could be checked each 5 secs, I don't know).

Thanks! :smile:

bug

All 12 comments

I think that components were designed to be independent. Do you have a critical example where this dependency is needed ?

@lordloki, @youle31 : I would like to hear your opinion on the subject.

Lots of examples:
If I create a component to handle the game rules (this kind of script is very common on the game dev world), the other objets in the scene will need to comunicate in some way with this script. For example, to say that the player/bot marked a new point or earned a new reward.

Or even better: If you create an Interface for the game (in a different scene), you'll probably want to create a component to control the interface, so when the player marks a point or level up, a cool animation will be displayed. And to make everything very organized, it is more interesting to have a function on the interface controller component that makes everything for you. If you don't do this way, you'll have to rewrite these event every time in different places and different scripts (bad modularization).

Another example: You create an enemy and now you want to apply a damage to this enemy. But your game is very complex, so the player, the other enemies and the environment could apply a damage. If you write:
enemy.components["EnemyController"].applyDamage(50)
you'll keep everything much more organized and modularizated than having the same function for every object that causes damage.

@panzergame maybe having components at scene level we can aid with these issues.
These scene components could execute before to object components...

What about initializing via steps.

Zero level = run first. 1 level initialize on frame 2 etc,?

On Fri, Jul 27, 2018, 1:16 PM lordloki notifications@github.com wrote:

@panzergame https://github.com/panzergame maybe having components at
scene level we can aid with these issues.
These scene components could execute before to object components...

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/UPBGE/blender/issues/763#issuecomment-408527741, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AG25WbqfrabF_TlmPdfGxc5st1joSb0Nks5uK3UagaJpZM4VjmKN
.

hi, I don't really know...

There are several types of logic: logic bricks, components, python with logic bricks.

Either you consider each logic type should handle all cases, either you consider they complete each other.

With the work you seem to want to do about logic nodes, it adds a new kind of logic.

What was interesting with python components imo was that users can create and share new custom kindof logic bricks... What if new logic nodes system handles custom logic created by users?

I don't really know, it's just general reflexions about logic systems

@lordloki I loved the idea. Add a possibility to attach components directly to the scene (and run those components always before the gameObject components) will be amazing!

@panzergame I added this section.

Edit: Another problem

In my game, I made some components that where used in various objects in different scenes, like the button component. During the development process, I had to make some changes on these components (like add or change the arguments). And the big problem is: I had to find every single button in the game to press the update button on each component. This was kinda painful.

What about an auto update? Like everytime the user opens the blender window (in case of an external IDE), or everytime the users changes the script inside blender (this could be checked each 5 secs, I don't know).

if I can intrude, i think it would be also useful to have (as for modifiers for example or logic bricks) the two arrows up and down to move components vertically (priority) This because if you have an object that has many components already setted, if you would like to add to this object a new component at the top, now you need to delete all the components and then re-add them after the new one, and resetting them again. (it would be great with the component window minimized)

Hi all,
Don't know if thisis the right place to ask this question, but I was looking for information on components and ended up here...

Is there a correct method to end a component? lets say I need to free some resources after using a component. I see the start() method, and the update() method, but how can I free my resources on ending the component usage?

I'm writing a component to output to a Decklink card, and works great on the standalone player, because it completely destroys all resources on exit, but when using the internal player I need to destroy my variables and release the card on ending blender game, otherwise it will be locked the next time I restart the gameengine.

Thanks in advance

Hello @UnidayStudio .
Why don't you make this call after all components initialized, for example, on second and later logic tick ?

Hi, sorry for ressurrectiong the issue, I'm trying to help by closing some not necessary issues here. Looking back, that first problem was my fault, not a bug or something like this.

Also, for the last problem, I made an addon a while ago that fixes the problem with a huge "reload all scene components" button:
https://github.com/UnidayStudio/UPBGE-Addons#component-helper

So I think it's ok to close this. :)

ok, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cederom picture cederom  Â·  7Comments

joelgomes1994 picture joelgomes1994  Â·  7Comments

marechal-p picture marechal-p  Â·  6Comments

IzaZed picture IzaZed  Â·  6Comments

RomStef picture RomStef  Â·  4Comments