Skip to content

How to add Gameobjects at runtime #31

Closed Answered by bijington
Bhuelsmann asked this question in Q&A
Discussion options

You must be logged in to vote

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 of BalloonScene:

  • One in the backing field balloonScene in your MainPage class
  • One is also created when you call gameSceneManager.LoadScene<BalloonScene>(GameView);

I would recommend multiple options to solve this issue:

  1. Modify the registration of BalloonScene to use AddSingleton or even AddScoped
    e.g.
services
            .AddScoped<BalloonScene>();
  1. Modify your OnAddBalloonClicked method to access the instance of BalloonScene loaded into the gameSceneManager. You could modify your code to look something like:
private void 

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
2 replies
@bijington
Comment options

@Bhuelsmann
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@bijington
Comment options

@bijington
Comment options

Answer selected by Bhuelsmann
@Bhuelsmann
Comment options

@bijington
Comment options

@bijington
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants