How to add Gameobjects at runtime #31
-
Hi, I am playing a little bit around with your engine. Nice work so far! :) With this clickevent I try to add a new object. Balloon is the gameobject, BalloonScene is my Scene.
In the scene is just:
In debug I can see, that the objects are added to the collection, but they are not rendered. You cannot see them on screen. They have another position , so its not, that they are stacked in z-axis or something else. Thx for your help :) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Thank you :). In theory that should work. As I am doing something similar in this file around line 84: https://github.com/bijington/orbit/blob/main/games/Orbit/Orbit/GameObjects/AsteroidLauncher.cs Is your source open so I could take a look? If not can you confirm that you have called Start from the game scene manager so that the rendering loop is active? |
Beta Was this translation helpful? Give feedback.
-
I tried a little bit around, but couldn't solve it. `
I added it to the ServiceCollection and in the scene I added it as gameobject. But now my app crashes with an
|
Beta Was this translation helpful? Give feedback.
-
Hi, greetings |
Beta Was this translation helpful? Give feedback.
I have had a quick look at the sample and I think I know what the issue is, you are registering
BalloonScene
as Transient and will ultimately end up with 2 instances ofBalloonScene
:balloonScene
in yourMainPage
classgameSceneManager.LoadScene<BalloonScene>(GameView);
I would recommend multiple options to solve this issue:
BalloonScene
to useAddSingleton
or evenAddScoped
e.g.
OnAddBalloonClicked
method to access the instance ofBalloonScene
loaded into thegameSceneManager
. You could modify your code to look something like: