Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's The Proper Way To Get Game Object From Editor Script As A Buffer? #696

Closed
vini-guerrero opened this issue May 17, 2024 · 6 comments
Closed

Comments

@vini-guerrero
Copy link

vini-guerrero commented May 17, 2024

Hello!, hey there.

Considering a Unity Plugin/Tool based on a custom Editor Window, what's the correct approach to load a buffer and retrieve it's GameObject (no instancing, just dynamic reference of the game object)?
I'm not storing the file locally, project requires a buffer since it will be used just for rendering a thumbnail.

// asset_glb - httpResponse.Content.ReadAsByteArrayAsync().Result Buffer
var gameObj = new GameObject();
var gltf = new GltfImport();
gameObj = gltf.LoadGltfBinary(asset_glb);

image

@atteneder
Copy link
Owner

Hi,

not sure I understand. You want to load a glTF-binary from a byte[] and access a GameObject without instantiation of a scene?

That is not really feasible. Do you mean you want to query (parital) information without displaying the scene or having the glTF's content show up? Please elaborate your use-case.

@vini-guerrero
Copy link
Author

vini-guerrero commented May 17, 2024

Yes, correctly, because the intention is for this dynamic Game Object to be used as input for Unity's PreviewRenderUtility (AddSingleGO).
It will be the source for Editor Window render a thumbnail of the mesh/material.
The goal is to not change user's project hierarchy or store unnecessary local files since it's just a thumbnail (multiple API results).
What's the recommended approach for loading this buffer with glTFast?

It's not meat for a "Runtime" in Game, rather an Editor tool, but not using Unity's Import/Export menus.

@atteneder
Copy link
Owner

I see.
There's no way around creating an instance. What I'd try is to create the GameObject(s) hidden by default (root GameObject not active and hidden in hierarchy).

You might have to create a custom IInstantiator, but maybe something like this does the trick:

// asset_glb - httpResponse.Content.ReadAsByteArrayAsync().Result Buffer
var gameObj = new GameObject("root");
gameObj.SetActive(false);
gameObj.hideFlags = HideFlags.HideInHierarchy;
var gltf = new GltfImport();
await gltf.LoadGltfBinary(asset_glb);
await gltf.InstantiateMainSceneAsync(gameObj.transform);

hth

@vini-guerrero
Copy link
Author

But this still requires it to run under Play Mode correct? Will throw the same error for Editor Window plugin.

@atteneder
Copy link
Owner

It should work in edit mode as well, as long as you don't run it async. See GltfImporter as an example.

@vini-guerrero
Copy link
Author

Thanks @atteneder I will give it a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants