Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AdrianFP · Nov 20, 2014 at 08:20 PM · controllerdontdestroyonloadarchitecturedesign-patternsviewcontroller

How should I integrate the MVC pattern?

Hi,

First of all, I'm sorry for my bad english. I'm wondering which is the best way to implement the MVC architecture pattern in Unity. I'm newbie on using this software but I've some experience in the programming world.

At first, I suppose I need to create an empty GameObject with the main controller script in an empty scene . This controller, should request for each view / scene / level in the game with Application.loadLevel. With this, the controller is gonna be destroyed, so I need to tell in Awake() to DontDestroyOnLoad(this).

But, how can the controller handle the inputs received in the view? The view, needs to send a request to controller, telling him: "the user has clicked this button of mine". In this case, the controller is defined in, for example, Scene0, and the view in Scene01. If I try to GetComponet() from the View, Unity says me he can't get the controller instance.

Can you give me a little example of this architecture pattern working?

Thanks a lot

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Immanuel-Scholz · Nov 20, 2014 at 08:31 PM

I am not sure you should use an Unity "scenes" as a view. To me, it makes more sense to group controller, view and models for an specific level into one scene.

There may be some model - gameObjects present over scenes (using dontdestroyonload). Just to pass on data between scenes.

Or you just could use plain C# classes not related to MonoBehaviour as data classes (although I recommend you use MonoBehaviours, just to save you some time writing editor code to debug the stuff).

Be aware that not much people use strict MVC coding patterns in Unity. Most people just go with the flow and put the stuff together somehow..

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I hook custom inspectors up to models? 2 Answers

How to avoid one engine class controlling the game flow getting too large 3 Answers

Decoupling state & graphics, while sequentially executing graphic updates 1 Answer

MMD How to export model and animations to Unity as 3rd person controller? 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges