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 JYKeith · Sep 11, 2014 at 09:58 AM · gameobjectprefabreplaceinitialize

GameObject Initialize or Replace with prefab

Hi All,

I have a questions about Initializing of GameObject with prefab.

There are two prefabs, almost same but have only a few differences. and load to prefabs and haven't been instantiated. It may have various children.

instantiate a gameobject with A prefab, and run... After a while, I'd like to replace only the data which are different between whole A and B prefab.

The instance may have dynamic values, I want it to remain.

I'm trying to manage UI with prefab. and making two prefabs for vertical and horizontal screen mode. So I need to reset recttransforms of all gameobjects(maybe.. but better to replace all the differences of prefabs, suppose UI is fixed and have one root gameobject) when screen orientation changes.

Is there any nice method to do it?.. PrefabUtility is in UnityEditor so I can not use it while running on mobile..

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 PAHeartBeat · Sep 11, 2014 at 10:18 AM

HI JYKeith,

If you are just making two prefeb for two diffrent screeen mode like Verticle / Horizontal. I thought it's will take much time if you need to change lt later.'

I thought you are want to support both orientation in your game like Candy Crush saga. so your game can playable in both orientation, and user can change orientation run time.

I suggest a tweek. why you instantiate? try repostion insted-of instantiate. repostion left and right according your aspect change. As Unity camera, it's never change size of camera in Y "height" (means you have camera orthographic size 10, Unity would make screen size 20, 10 up side from camera cetner and 10 botam side) after that it's would calculate camera width using aspect ratio of screen. so it's follow this equation to crate render viewport for orthographic camera.

OS = Orthographic Size = 10 WPH = View port Height = OS x 2 = 20 WPW = View port Width = WPH * screen aspect

Landsacpe orientation WPW = 20 * 1.33 (screen aspect of iPad or iPad Ratina 4:3 landscape), so Now WPW = 26.6. according it your view port for landscape orientation is 26.6 x 20 unity units.

Protrait orientation WPW = 20 * 0.75 (screen aspect of iPad or iPad Ratina 3:4 Protrait), so Now WPW = 15. according it your view port for landscape orientation is 15 x 20 unity units.

I use this simple math to repostion HUD / UI object as per differant Devices of Apple or Android. and it's work good in our games. may it's usefull to you.

So I suggest don't used diffrent prefebs for different orientation. just repostion your game object based on virtual center of screen.

Comment
Add comment · Show 1 · 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
avatar image JYKeith · Sep 11, 2014 at 10:27 PM 0
Share

Hi PAHeartBeat! thank you for your answer.:-) I'm working under unity 4.6 new UI system. So basically the UI elements change their position according to screen resolution. but sometimes I'd like to have different layouts for each screen orientation which seem difficult to make it with something like "LayoutGroup" of new UI system. It's complicated....

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

Replacing empty gameobjects with prefabs 3 Answers

Change the colour of a prefab with a script. 1 Answer

How can I tell what prefab a GameObject belongs to? 2 Answers

Swap tree prefabs at runtime 1 Answer

Spawn Prefabs 1 Answer


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