Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Way to get objects script from generator
#1
Heya again, sorry I know you sorta answered this question in other posts but I was curious in a more broad sense. 

My game uses generators to create gameobjects on splines that have behaviors. In this case my game objects are called "Blocks" and have a bunch of components that drive them. The block is initialized via a setup, and all the modules that are a part of it follow suite. 

I have a few questions

1) Is there a way to get direct access to this type in a fast way? Currently I use OnRefresh to grab the list of them via GetComponent(). GetComponent Ive always heard is rather slow, and considering this is a realtime editor, I was wondering if there was a faster way.
   
2) Are the gameobjects created pooled? I know you said yes however I'm wondering if I were to call a setup function for my blocks, would that setup persist when generating more? 

3) This is more asking for your opinion or advice. 

For spline walls, I generate a few different things. 

- Wall Segment Curvy Generator, this generates walls along the spline but not on any of the Control Points. 
- Custom Tower Generator, this just spawns towers by checking each control point. Currently it can overlap them, but I plan to have a system that checks a tower exists already. Based on the wall type Ill prob have it override it. 
- Collision Collider, this is a collider I generate along the spline to handle checking if I'm intersecting (to not allow building) as well as spline snapping. 

I then feed this all into my core modules and handle behavior such as wall destruction, or previews for building and things.

My question is if you think the way I'm handling it makes sense (mixing generators/custom spawners), or if you think it'd be better to just write my own custom generation system based on all the questions I've asked.

This game needs to run fast as I'm intending to make it for pc/mobile for the client which is why I'm asking so many questions regarding performance as well as what you think would work best.


I really appreciate all the time you've taken to help me out. Any suggestions you have are welcome. 

I've inserted an example of my current layout.
   
Reply
#2
Follow up on this question, I tried using the createGameObject module to get my wall game objects and call functions.
Using the OnRefresh callback I was able to access the items via createGameObject.GameObjects.Items.

This worked however in an attempt to slightly optimize my preview stuff (basically just applies a material property block to each wall when preview toggle is set) I tried to optimize this by having OnRefresh add the Preview component I needed to a cached list. On every refresh, I'd clear the list and update. This way if I moved the cursor slightly and the preview changed but the wall amount didn't, I wouldn't need to regrab all the wall modules again.

The issue is that I think the way the pooling works, its constantly changing out the objects anytime it regenerates? And thus my caching doesn't work all the time and I'm forced to rebuild the list of the wall modules.

There has to be some better way to handle this right?
Reply
#3
Hi
I will not be able to answer everything today, but here are some answers:

1- About GetComponent:
Use GetComponents instead. Read their documentation page to be sure to understand what you do.
Also, leave optimization for after your implement your idea. Most often than not, what makes ones implementation slow is not what he/she expects. The profiler should be what guides you when optimizing.
Finally, about those non-Curvy-Splines specific issues, it is better to look on the Unity's forum, answers.unity.com, and their doc. I am very good at Unity, but surely there are other people well more experienced than me on everything that is not Curvy Splines, and might be able to answer you more quickly.

2- If Pooled objects implement FluffyUnderware.DevTools.IPoolable, their OnBeforePush and OnAfterPop are called. Take a look on that interface and its usage to better understand how that works. You can use that interface's methods to make any code execute when reusing pooled objects
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#4
(05-15-2023, 12:40 PM)_Aka_ Wrote: 2- If Pooled objects implement FluffyUnderware.DevTools.IPoolable, their OnBeforePush and OnAfterPop are called. Take a look on that interface and its usage to better understand how that works. You can use that interface's methods to make any code execute when reusing pooled objects


I tried setting my objects to use that interface and it didn't call the methods. Am I supposed to make a custom UnityObjectPool or something?

Edit* Yeah sadly unless I'm missing something, getting access to my scripts doesn't seem as straight forward as Id like. It seems like I need to make a custom pool, then make custom modules for the generator. 

Unless I'm mistaken and there is a simpler way... Sad


All I'm trying to do is generate my own scripted prefab walls, call an initialization on creation, and have access to them right after. This way I can do things like call a preview script.

As of now I'm using a modified generator that uses createGameObject. This unfortinately doesn't give me any direct access to my scripts. Instead needing me to loop through all the objects and grab the component. 

But this also has issues due to the order. I'm unable to accurately get most current generated objects to apply things. Instead I get a mix of old/new.
Reply
#5
Sorry for the constant posts, I'm so close to sending this to the client but this strange bug is holding me back. Ive tried so many solutions...

Every frame I'm accessing the ActiveObjects, grabbing the component I need, and changing the game objects scale (for visualization purposes) based on if its in preview mode, and if its blocked from building or not.

This isn't performant but its just me trying to make the base system work. 

The problem is that the pool of objects it accesses seems change before I'm able to access it. I've tried OnRefresh in the CreateGameObject module, checking every frame, ect..
and can't seem to figure out why it wont let me change the values.

I also can't get the IPool working.

Image of the code.

I had to manually call my Setup function (in Start) again since it doesn't always seem to fire off right away.
   

Video showing the issue. 



Is there simple way to just get access to the created objects (and its scripts) after its finished generating them so I can toggle/modify things on them?
Reply
#6
Here is how to do it, using a simple example with a Create GameObject module.

.zip   4 Lupos.zip (Size: 8.96 KB / Downloads: 1)
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
And here is another version that uses the Deform Mesh module.

.zip   4 Lupos Mesh Deformation.zip (Size: 9.04 KB / Downloads: 2)
Do not import both zips' content at the same time, some scripts share the same meta guid.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#8
The zips I attached are examples of how pooled objects can have an initialization code called when taken out of the pool (using OnEnable, and the pool's "Auto Enable/Disable Items" option (set by default to true).
Also, an external script will call specific code of the pooled objects (your preview code) when the module is refreshed.
Also in the case of the mesh deformation example, the script from the input gameobject is applied on the output game objects.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#9
The IPoolable approach is not the simplest in your case, so I didn't use it
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#10
Really appreciate this, you've really helped me figure out where to go.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation Extending Curvy Generator for Advanced Lofting - Feasibility Check amutp 2 4 Yesterday, 07:25 AM
Last Post: amutp
  8.8.0 is live, and it improves Curvy Generator greatly _Aka_ 0 5 Yesterday, 03:23 AM
Last Post: _Aka_
  Adjust radius of generated mesh via script? Shackman 1 3 03-26-2024, 01:12 PM
Last Post: _Aka_
  Generating GO only on CPs in Generator GameDeveloperek4123 1 6 03-04-2024, 11:06 AM
Last Post: _Aka_

Forum Jump: