Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[BUG ?] - GameObject.CreatePrimitive()

Discussion in 'iOS and tvOS' started by giyomu, Dec 12, 2011.

  1. giyomu

    giyomu

    Joined:
    Oct 6, 2008
    Posts:
    1,094
    Plop !

    ok something that surprise me a bit, so i wanted to share see if this worth a "bug submit" or a normal behavior that i did not get since early day of human being creation ^^..

    using this method to create simple block on screen , i have no primitive mesh object in my scene or in my project ( to give you an overview I am doing just a breaker clone and create my block on the fly that way, so I do not have yet any kind of mesh prefab etc..)

    so to summarize >
    -----------------------------------------------------------------------------------------------------------------------------------------------------------
    step 1

    build using mscorlib
    no mesh primitive in scene
    no mesh primitive in project

    Xcode crash with following message on gdb :

    ---------------------------------------------------------------------------------------------------------------------------------------------------------------
    step 2 >>

    build using disable for stripping
    no mesh primitive in scene
    no mesh primitive in project

    Xcode >> Work OK
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------
    step 3 >>

    build using mscorlib
    add mesh cube for example in my Resources folder Or add in scene

    Xcode >> Work OK


    Is this something expected, seem like because there is no mesh object the components we usually have on our Go get skipped form the build..or something like that ..
     
  2. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    This sounds like it has to do with Strip Bytecode working properly.

    Strip Bytecode removes any unused APIs and functions on a function by function basis.

    Your game had 0 MeshFilters, and you tried to use a MeshFilter. It's interesting that they can strip UnityEngine itself, and have some sort of helper for determining which components you have in a scene, as I didn't know it would check through added scene files/resources. Your best bet would be to create Link.xml in your root Assets folder that looks like this:
    Code (csharp):
    1.  
    2. <linker>
    3. <assembly fullname="UnityEngine">
    4. <type fullname="MeshFilter" preserve="all"/>
    5. <type fullname="MeshRenderer" preserve="all"/>
    6. <type fullname="BoxCollider" preserve="all"/>
    7. </assembly>
    8. </linker>
    9.  
    This xml file is used by the project builder's Bytecode stripper to preserve specific namespaces and classes. You can then force the Bytecode stripper to include those classes regardless of their use in a specific scene. Overall you could consider it as an oversight in whatever Unity is using to preserve certain types based on what scene they are in (CreatePrimitive is not referencing those types properly), so it could be a repotrable bug as well.
     
  3. giyomu

    giyomu

    Joined:
    Oct 6, 2008
    Posts:
    1,094
    Thanks Ntero,

    yes it kind of make sense strip side as it does it job properly ( too much in that case haha ) , but as you said using the fct CreatePrimitive should prevent those references to get skipped ..

    I am going to report it as a bug eventually so then UT will see ^^
     
  4. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    Actually looking at the error and seeing GameObjectUtility.cpp it could be similar to some SQLite issues with Bytecode stripping; Native code elements of Unity call back into the Mono side to call specific functions. The Bytecode stripper cannot parse non-Mono elements to determine who is calling what.

    If that's the case the only fix they would add would likely be adding it to the default link.xml (which already has BoxCollider set to fields rather than all). This file is located in you Unity.app if you inspect it and search for link.xml.
     
  5. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    Got similar problem with assetbundle on Unity when loading and instancing a model.

    It seems that if you create a private variable of each type missing at the beginning at the top of your script, this remove the error.
    But that is very tricky.
    I found a thread speaking about this issue last week where they spoke about this tricky method... will try to find it tomorrow...
     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Sorry to necro this thread, but I've just run into this same issue, so I'm curious whether anyone here followed up with a bug report. I'd love to sign on to the existing bug (from 2011?!?) rather than create a new one.
     
  7. JungJik

    JungJik

    Joined:
    Jun 23, 2020
    Posts:
    5
    I faced same issue. and I understand why, but unity doc doesn't show how to fix it. just say "make a private reference."
    I did it but it doesn't work. and it happens very randomly.
    and unity says "may fail in runtime"... may? may?
     
  8. JungJik

    JungJik

    Joined:
    Jun 23, 2020
    Posts:
    5
    I think it is a bug but Unity doesn't think it is.