Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

Temporarily destroying the gameobjects

Hello,

I am trying to work with instantiate and destroy methods of unity.But when I have destroyed a particular object using destroy(), I am unable to get it back.

Is there a way to get the destroyed objects back ,or we have some other set of methods to use ,for temporarily destroying the objects and getting them back when needed.

I know this is unity related question,but anyone having idea regarding this would be helpful.
Thanks

Tagged:

Answers

  • Options

    @Afreen_Firdous26,

    It sounds like you don't really want to destroy these objects, but instead just hide them for a while. You can used a game object's "enabled" property to accomplish that rather than the destroy() method.

    Here's a tutorial about it: https://unity3d.com/learn/tutorials/topics/scripting/enabling-and-disabling-components

    James Ashley
    VS 2017 v5.3.3, Unity 2017.3.0f3, MRTK 2017.1.2, W10 17063
    Microsoft MVP, Freelance HoloLens/MR Developer
    www.imaginativeuniversal.com

  • Options

    Hi @james_ashley,
    Thanks for replying.

    Is this enabling and disabling not similar to GameObject.setActive() method?

    Actually when i am carrying all the objects through out my application,it is increasing my application size.
    So, my question is instead of carrying all the objects,can't we use them when required and destroy them when not required and again get them back when needed.Do, we have any set of methods for doing this?.

    Thanks.

  • Options

    Destroying a GameObject removes it, all it's components and children from the scene. To get the GameObject back you will need to instantiate a new one. If you would like to persist the state of the GameObject you could serialise it before you destroy it then read it back in when you want it back although this will entail another performance hit.

    Are you sure setting the GameObject inactive won't solve your problem?

  • Options

    @Afreen_Firdous26, @james_ashley is correct. If you want to temporarily "remove" an object without losing all of its data, the easiest option is to call setActive(false). You can then later call setActive(true) to bring it back.

    One option you could look at is using prefabs combined with destroy. However prefabs only work for defining how things will be when they are first instantiated. If you make changes to those instances and destroy them, those changes will be lost.

    If you really do need to destroy objects but also maintain your changes to them, you will need to look into a serialization solution and a way of storing the serialized data on disk. A thread like this one may help you find a solution.

    I'm a little confused about your statement "when I am carrying all the objects throughout my application it's increasing my application size". Are you referring to the size of your application binary or the amount of memory your application consumes?

    If it's the size of the application binary on disk, this should increase moderately as you define new object types but should only increase minimally for each instantiate of that object.

    If you are referring to the amount of memory your application consumes at runtime, the only way around this would be to destroy objects you're not using. This would require the use of prefabs or serialization as described above.

    Our Holographic world is here

    RoadToHolo.com      WikiHolo.net      @jbienz
    I work in Developer Experiences at Microsoft. My posts are based on my own experience and don't represent Microsoft or HoloLens.

Sign In or Register to comment.