#archived-code-general
1 messages ยท Page 317 of 1
Im writing this tool for the use of non-technical people. So I'd rather get these sort of things done automatically
This is for use as a university experiment, so the students who will be using this won't have a background in game dev or understand how the unity editor deals with docking windows.
I agree this seems like a silly thing to need to do, but for me its worth getting rid of as many potential issues as possible with this sort of thing
If its not possible then I know you can save and write specific layouts through code so I will do it that way, but just wanted to make sure I wasn't missing something in terms of accessing tab data from an already existing window.
how can i prevent this from happening?
basically i kept my gun too close to the camera and now it cuts itself and shows its inside.
pls ping me if u have an answer because i am going for lunch and will be seeing the replies after i come.
thanks,
MrcJoc
also idk where to post this problem i post in genrel
- move it away
- modify the near clipping plane of your camera
It should go in #๐ปโunity-talk
This is NOT a coding question
@leaden ice do you know if this remotely possible through script? if not then I will just do the other approach but I do mean this as a code based question for custom editor scripting.
Look at the last overload at the bottom https://docs.unity3d.com/ScriptReference/EditorWindow.GetWindow.html
Ah thanks, I had a look at this class for implementation but didn't see the list for desiredDockNextTo.
And yes, sorry I didn't realise there was a channel specific to editor extensions.
Ill use that in the future! Thanks ^-^
I have conflict in the interface , I can't make an alias for each library so how to resolve it ?
error CS0433: The type 'IAsyncEnumerable<T>' exists in both 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' and 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
Use the full name (including namespace) when referring to either one in the same script
how syntaxally
Microsoft.Bcl.AsyncInterfaces.IAsyncEnumerable
before the interface ?
Use it when referring to it
Or remove one of the namespaces you don't need
Right, then refer to it including the namespace
supprise
Are you sure you have installed the Nuget package?
locally yes
Well, you cannot use it, so you haven't
also Nuget package manger acting weird !
I did in unity , other script use it without any problem
You have done it in Unity? Nuget packages may be troublesome there
Are you suge you have placed the dll correctly?
yes
Well, it doesn't work, so, probably, no
as it cause conflicts I need to build custom dll library which cast it to the correct namespace -alias
I extract all nuget manually because Nuget for unity cloudn't decide which version so I extract all nuget-s that target 2.1 api {and all its decencies } and it seems work just fine in unity
But it doesn't work in your code though
The issue is this is for an individual audio source. Meaning I'd have to go around multiple points in my code and stop each individual audio source. I was hoping for a way to stop all audio sources globally.
Either store them in a List or use FindObjectsOfType<T>
hello I want to make an attack I have 2 meshes for it and want to do it such that when Q is pressed the attack mesh is switched to from the standing mesh pls help
I have some problem... So generally I know how to communicate the scipts, get the components bla bla. but the real is issue is that I'm not able to create a system that works properly and effectively. So I learned that I should check it out the scriptable object lesson in unity but also I'm curious is there something that u should suggest me to learn before this subject?
What issues are you seeing with the way you are currently doing things?
What kind of "system" are you looking to build
Seems really vague
I'd make sure you really have mastered references and prefabs and lists and things first
Thank you very much
I want the object interact each other but when i do it with only prefabs its really a lot work to handle all things. So I know need something like scriptable objects system. But also i asked if there a more system like that i should know. So also Iโll take a look at that too
[requirecomponent ()] attribute forcefully adds the specified component to the game obgect if it is not present. Is it possible to instead make it so that you can't add this script to the game object if the required component is missing, and not create it automatically? I want the script in question only be able to be added to specific object types, not turn any object into object type the script is intended to be used with.
IIRC some native Unity script don't allow to add itself to object with missing component, so I want to replicate that behavior.
I changed the execution order for a script in order to make it init before others however after doing so now the project always stalls on start. The editor freezes and doesn't allow any input through the ui or even the close/minimise/restore/maximise buttons or moving the window itself. Unity's RAM usage keeps going up until it maxes out around 80-90% (making my total ram usage about 90-100%). Then just sits there and can only be closed through task manager.
I've tried reverting the execution order changes, changing the order to something else, updating Unity Hub, and restarting my computer. Other projects seem to run just fine, it's just this one. I've attached the current execution order (underlined one is the one that I have tried removing and is the one I added in). The execution order UI seems a bit bugged (or just isn't working how I expect) as sometimes when I hit apply it'll revert or change the order before applying.
Apologies if this is the wrong place to ask, I'm unsure where to ;-v-
dead loop in your script
changing execution order solves nothing, you need to figure it out
changing execution order was to solve a different issue, I'll check any loops that this fix would make accessed now.
yeah, it seems to have been a faulty while loop. my bad there, thank you @fervent furnace
erm
what is this
why is it doing this
Hello,
I have a problem with the Time.deltaTime.
I have a project which is a board game inside unity and i need to be able to clear the board when starting a new game. I'm using the Time.deltaTime to move the pawns and animate the movement and its working perfectly.
But once i've cleared the board (by deleting all childs and making it back, with the same functions i use when creating it), the Time.deltaTime used in the animations does not grow anymore ๐ค
I have no idea where it can be broken so pls help me ๐คฃ
Screenshots :
1 - the code to move the pawn, its called in a subroutine
2 - the subroutine call
3 - console output when its working (before clearing the board)
4 - console output when its broken (the deltatime is not increasing anymore ๐ค )
I'm guessing at some point you set timeScale to zero
looks like you set timescale to zero and forgot to set it back to 1
oh, its a group project and i never heard of that ๐
looks like i'm gonna ask some questions to my teamates ๐
thx i'll check that
i don't know where it was set to 0, but i just put it back to 1 when creating the board and its working ๐
if something else is broken in the code i will think about it later ๐คฃ
Thank you very much ๐ซถ
it would be a good time to learn a bit about your IDE, you should be able to do a search across the codebase for uses of Time.timeScale
find where it's been used and why
yes good idea
i found it and i know who i need to kill ๐ ๐
(i'm joking i'm not gonna beat my friends)
Hello there. If I have a code that place, move and create a ton of object (World creation). What is the best way to reduce the waiting time and enable the loading bar to move (not 25s between frames). Jobs system, System.Threading or Inumerator?
https://discord.com/channels/489222168727519232/1062393052863414313 is your only choices probably, you cant multithread instantiate
How can I unzip a .zip file?
What do you mean?
within a script, how can i unzip a .zip into a directory
oh, ok. More clear now.
Find a C# zip library. Pretty sure there's one in .NET probably
Dots, I have heard about it. Do I need to modify the code heavily if I just need to place a lot of object and no dynamic interaction?
That's a question for dots rooms. sry
Spread out instantiation over multiple frames
In a Coroutine for example
I see, I will use a Coroutine for instanciation and a jobsystem for other script.
why can this code detect if theres no , but it cant replace it
string is immutable
so any method does nothing on the orignal string, they return you a new string
hello, anyone knows how to make a circular button ?
when i use a round sprite, you can still click it as if it was a rectangle
thank you
hey
i have this VERY nested list with lists and stuff inside... how can i get to Currency Code and Currency Price by item name and category name?
my brain is fried
I think I'm gonna blow your mind - learn about Scriptable Objects, I think they're perfect for your usecase
And dictionaries, too
I have a scriptable object that is unable to use the GetComponent method because it requires monobehaviour, but my object is currently inheriting Scriptable Object, so I can't add it on. I have another script inheriting this object as well.
I'm guessing I could create yet another class that inherits monobehaviour for yet another layer of monobehaviour, but is there a better approach to being able to utilize GetComponent?
And dictionaries, too
cant realy serialize dictionary and dont wana use adons to
but i forgor about scriptatbel obejcts so ty for remining
you can serialize lists, and create a dictionary from the serialized list, dynamically at runtime - and reference the dictionary when coding!
Unless you really need the dictionary in edit mode
have a list for editing stuff in editor, and a runtime-only dictionary for referencing it from code
also blow my mind failed
this data is remote
afair s.o. is local
sory if me stupido its 12 am
you can't do component from a scriptable object, because a scriptable object is just a random file effectively, not attached to a gameobject
you can go gameObjectVariable.GetComponent from within some function that's on a scriptable object, or you can just run what you need on a monobehaviour and just pull data from scriptable objects
i get it froma server
you could use addressables to pull the SOs from the server as well, perhaps
ok by serevr i mean plafyab
hwo do i dio this tho
you either loop through the nested lists every time you want to access an element, and compare the data in the list (like name) with the data you wanna grab
or you create a dictionary at runtime, using the data from the list
I just found that I can do this:
GameObject.FindGameObjectWithTag("Foo").GetComponent<Bar>();
This works fine for my purposes. Thank you.
FindGameObjectWithTag is pretty slow. Doing it once is fine, doing it a couple of times every frame will slow things down. If you can, I'd pass the gameObject Foo into your function on the ScriptableObject as a parameter instead
I'm surprised to hear that. I have always been told to avoid finding GameObjects by names and to only use tags since it's a lot faster, but I didn't know that searching by tag was also slow.
it's definitely faster than finding it by name, yes
but it's not particularly... fast
and also hope you don't have multiple objects with that tag, too
it's best to just pass it as a reference, really
I only associate one object per tag, and it's also not being ran in an update method. But in that case I'll try to avoid using that when I can.
preformance wise it'd be fine then, but I think it's good practice to pass it as a parameter instead
or optionally, consider making it a singleton - that's much faster, and also it's a cool pattern, I'm using it all the time
This is a guide a friend made
What you're doing is equivalent to C tier.
Hey everyone, how can i use the object the raycast had a collision with (interactable) in a future update cycle to disable a component of that object? I have tried a lot of different things, but nothing seems to work
Store it in a class member variable
i am trying to make my enemy shoot in a parabola curve , someone knows how?
nothing on google...
Copied your question word for word.
interactable is already a class variable though, i think
Not in that script
Ok thanks, i will search around a some more
What do you need to search around for? Just make the variable in the class (not in a method) and assign it in the raycast condition body
It works, but the outline isnt cooperating, just have to fiddle some more. Thanks for the help
Does anyone know if its possible to set the cursor to the hand? Like the default OS cursor when you hover over a button
Without manually setting my own cursor icon of course
No you need the cursor texture
You need to use native libraries for the operating systems you intend to support. For Windows, you would need to P/Invoke the SetCursor function in user32.dll.
Thank you, it works perfectly now.
How can i get the object size of a probuilder mesh filter? i notice there's a read only property in the editor which would be super useful info in a script but i'm not sure the property name or how to access it, the tooltip or any buzzwords don't show up in a search on the ProBuilderMesh script
This is the property for reference
that code's in a custom editor (ProBuilderMeshEditor). It's merely reading mesh renderer bounds.size
Ah, i already tried that but all the properties were just 0. I was getting the mesh renderer of a prefab, but i tried it again with the prefab instantiated this time and that seems to work fine

anyone here any good with splatmaps i got a question?
im trying to get my terrain to update in the size of a collider. basically my player stands in the collider hits f and the terrain in the collider should be updated with a new texture. I've been debugging and i can tell its going through the function in its whole and im grabbing the correct layer in my terrain textures but it's not updating the terrain.
its just a flat terrain for a 2.5D game so nothing crazy is going on with the terrain at all i just dont know what im really looking at lol
you might like to share your !code. And please read the bot message before posting it
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Thank you! https://hastebin.com/share/agiwameviq.java
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I do know that it passes in the correct collider
where do you define your splatPrototypes
They are in the terrain layers of my terrain component
so index 0 is grass index 1 is soil
if you are changing texture should this
splatmapData[0, 0, 1] = 1f;
not be
splatmapData[0, 0, 0] = 0f;
splatmapData[0, 0, 1] = 1f;
also you only appear to be changing the texture for one single point
like one pixel?
yes
you are absolutely correct i just saw that
this
float[,,] splatmapData = terrainData.GetAlphamaps(mapX, mapY, 1, 1);
get one point of width and height at the specified position
i see now, apologies this is like week 1 of ever touching a game engine lol any ideas on how i could expand that to cover the amount of terrain a collider is covering?
drop the code in for loop to cover the area of the collider, not the most efficient way but the easiest
thank you very much for the help i've been on the struggle bus with this for a while! terrain has been a very daunting aspect for me when it comes to scripting it.
you are not alone, the vast majority of people take one look at the data structures and just give up
currently having issues figuring out how to preserve some player data when transitioning between scenes - is it common practice to store player data in some singleton game manager rather then the player, or call DontDestroyOnLoad on the player and just move them/disable them when transitioning to scenes?
Hey, Input Controller gives me a Verctor2 for 8dir movement which can be: [1, 1] or [1, -1] or [0.67, 067](for diagonal) etc.
Is there a way to clamp Randomly generated values to fit the above?
What systems people use? I want to have Npc walk in a random direction without having to type clamp(value, 067, 1); or something similar.
do I convert angle to direction instead and move npc in a random angle?
Vector2 direction = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.right;
I can get random angle by getting random number 0-7 and multiply by 45
Are you sure diagonal is 0.67? A 45ยฐ diagonal vector of length 1 is 0.707, 0.707
That was an estimate, but ye
You can calculate a point on a circle with a random angle:
var randomAngle = Random.Range(0f, Mathf.PI * 2);
var pointOnCircle = new Vector2(Mathf.Sin(randomAngle), Mathf.Cos(randomAngle));
Sorry, I missed that it's limited to 8 directions.
Yeah I am testing above code, for some reason it doesnt work exactly the same as player movement.
But its close
I mean this
With 8 limited directions, I would just pre-calculate the directions into a lookup table/array.
why not just calculate the 8 direction vectors you want and hold them in an array, then randomly select one of the entries in the array?
Even if player movement uses input system for its direction?
sure
Alright, I guess that sounds like a plan then haha, I will give it a go
ok I see the issue with my code
x = 5.960464E-08
y = 0.9999999
Guess I will just make a dictionary of vectors so I can use Enum for a direction too in case I want to create a path for npc later.
Hello everyone, I'm having an issue with Unity: I'm creating a card game and working on a deck from which players can draw their cards. However, every time I actually draw a card, this error appears in my console, and since it doesn't give me much information, I really don't know where to go. My code doesn't have any string of the TYPE type, and when I checked my code, everything seemed to be working fine.
I know I didnt show any parts of my code, but it is because I dont know if this is the exactly place to put it or if I should create a post
For the love of god open your console window
Read the full error message
And the stack trace
Its because theres nothing specific there, the error message is simply:
type is not a supported string value
UnityEditor.RetainedMode:UpdateSchedulers ()
That's because you're only looking at the first line of the error
However it's clear that this is an editor issue just from that piece
Does it mean the error is in the inspector?
What are you hoping to find and where are you looking? It's likely a Unity bug. Report and research it, and move on
Should I just continue my work like nothing happened then?
I made my recommendation
Is this in regards to custom editor scripting?
The only third party I using is LeanTween, but I'm not trying to modify the editor, at least I didnt meant to
Are you able to determine which object the error is related to?
I think the problem is related to the Card GameObject, since the error only occurs when I try to move a card from Deck to Hand
Maybe you ought to show the code that moves the card from deck to hand.
Should I create a post to do so?
Also, does this occur with nothing else in the scene but the two objects?
You wouldn't want to be investigating something unrelated to the problem - XY problem.
Yes
Hmmm... Somehow I just closed the program and oppenend it again and now it seems fine again
Idk what happened, but Ill just report it and move on
is there a way to do like list.indexof but for a 2d array?
might just switch to a dictionary
you know indexOf is basically just a for loop under the hood, so write your own
How to make the grid follow the object direction, instead pf the world direction???
to get a value from a Dictionary based on a key. Returns true if found, false if not
I mean yeah
but can't you just do if(Dictionary[Key])?
no. you can do if (dictionary.Contains(key)). but that does not return the value for the key if found
ah
Your version will throw an exception if the key is not present in the Dictionary
sorry for being stupid
this will throw a KeyNotFound Exception if the key does not exist
really? hasn't done that for me
oh because I used containskey ๐
im just dumb
disregard everything I say
A d.ContainsKey() followed by a d[] can indeed be simplified down to a single d.TryGetValue() call
oh lol I think I am about to use tryget like rn
thats crazy
I shan't have questioned the unparalleled intellect of people who write programming languages
!learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
Actually, this has nothing to do with writing programming languages, but more to do with designing API calls
It's used here and there, eg. TryGetComponent<T>(), int.TryParse(), etc.
fair
Attempt to do X and return a value whether that succeeded, and if it does, get another value as an out param
Is there a way to get a unity event from another script in animation? (The animation is on a game object that dosen t have the script), without using another script
what do you mean by "get" the event?
Use all the normal means of referencing things.
i mean to use it in another animation
so at a time in the animation something happens
Use an animation event
that s correct
As for how to communicate with another script that's just a basic question of getting a reference to it
I am passing input parameters to an abstract class' method. Another class that is overriding the method is receiving the input parameter. However, none of the properties of the input parameter are showing up in intellisense. How do I pass an object via abstract class?
public abstract class EnemyLogic : ScriptableObject
{
public abstract void Finish(FooClass foo);
}
public class Enemy : EnemyLogic
{
public override void Finish(FooClass foo)
{
foo.??? //(None of the public properties in FooClass are visible or accessible here)
}
}
What does FooClass look like?
if intellisense isn't working it could be a sign that your IDE is not configured properly?
It says it doesn't contain any definitions if I do foo.PropertyNamehere, even though I know for a fact the property is there.
public class FooClass
{
public int Digit { get; set; }
public Vector2 ObjectPosition { get; set; }
public float YOffSet { get; set; }
public bool CurrentlyAttackable { get; set; }
public string ObjectType { get; set; }
public bool IsSpawnable { get; set; }
public GameObject SpawnedObject { get; set; }
public int Health { get; set; }
public Vector2 HammerPosition { get; set; }
public Vector2 CurrentObjectPosition { get; set; }
public Vector2 CurrentDirtPosition { get; set; }
public GameObject DroppedLoot {get; set;}
public Vector2 DroppedLootPosition { get; set; }
public Enemy EnemyData { get; set; }
public Hazard HazardData { get; set; }
public TreasureChest TreasureChestData { get; set; }
}
Is your IDE configured?
Yes, I only have issues with intellisense in this abstract class.
Also do you have any other syntax/compile errors in the code?
I don't see any reason why IntelliSense shouldn't be picking these properties up
I doubt it's related to the abstract/override thing
Anyway at worst this is an IntelliSense problem. The code you wrote is correct.
is FooClass recognised? Missing namespace?
regen project files ?
Unfortunately it's more than intellisense, I can't modify or access the properties.
how do you know? What happens?
Are you getting an error?
I can't build my code.
foo.Digit = 1
FooClass does not contain a defnition for "Digit" and no accessible extension method 'Digit' accepting a first argument of type 'FooClass' cloud lnot be found (are you missing a using directive or an assembly reference?)
If you right click FooClass and click "go to definition" or "go to declaration" where does it take you?
It takes me to the class.
Are you getting this error in Unity too? Or only in VS?
I would guess some combination of:
- More than one FooClass defined
- Assembly definitions are involved
- Namespaces are involved
Can you post the !code for it?
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
For specifically the file that pops up under "Go To Definition"
I think I know what the issue is. I had tunnel vision and missed the fact that FooClass has another class wrapped around it. I'll report back soon.
ah then yes you need WrapperClass.FooClass
But your guess would be on point if this is the issue.
Yes, that was my problem.
I didn't realize that the IDE was trying to help me by automatically adding the wrapper class as a static using statement at the top. So I didn't realize there was a problem since I expected it to work without the wrapper class name.
The IDE has been trying to help me with this the whole time but in the end I think it just made me develop a bad habit. Oh well, now I acknowledge what's going on so I know what to look out for.
Thanks for the help!
So, when it comes to input maps, I've been thinking of creating a combined maps system, where I have say a "Movement" input map, and a "Weapon Sheathed" and "Weapon Unsheathed" input map, and activate multiple at the same time. I do see that this can't be done with the "Player Input" component, but I have more of a theoretical question: does it make sense to represent input map sets as a FSM? It seems like a fairly logical approach. Has anyone tried doing it that way, and does anyone know of any packages (ideally FOSS but if not, asset store) for it?
FSM doesn't make a lot of sense to me here unless it's a layered one. From your example here we have a Movement map and then sheathed/unsheathed weapon maps which presumably are independent of the moving one
That's true, I was balancing configuration complexity with programming complexity. I figured not too much work to put the Movement map on all relevant, though yes, layered seems more logical
But more work to implement code-side haha
Since you actually need to keep track of whether edges cross a layer boundary, rather than using a simple graph
Another question, from what I've been reading, Unity's "SendMessage" and "BroadcastMessage" functions aren't great. Do people usually just use hardwired events, or do you roll your own message bus?
How do you guys handle save&load usually?
Mine is a sandbox game which means that there's uh... A Lot to save
json / prefabs
My question's bit more like, if there's for example an undefined amount of varied enemies that needs to be saved, how do people normally go about it?
json
You save whatever you need to save
You can't save via a prefab now can you?
You can. Applying the changes to the prefab won't make it lose them after the game is finished
The same way you store anything in an undefined amount, a list of these objects
If there's information that can be stably derived from a source other than the save, use that. For example if the game involves a procedurally generated map, often you can get away with just saving the map generation seed, rather than all the generated map data.
If it's modifiable later, e.g. Minecraft, you could just save the modifications, rather than the whole world of blocks, for example.
Everything is destructable and then you can place new stuff too '^^
This is all hypothetical and really depends on the specifics of your game
You have two choices:
- Save the absolute state of the world
- Save the info needed to generate the world as well as modifications players make later
Well, I've got a terrain manager storing all the data and stuff
But not in a manner just so easily saveable, I believe
so I may start a aside project that scripted in python , what are my option here do I use https://docs.unity3d.com/Packages/com.unity.scripting.python@2.0/manual/index.html
or better go with iron python inside .net directly
If you have a huge amount of data, something like JSON is also not likely feasible for size reasons. You would want to consider either a custom binary format or something off the shelf like protobuf or MessagePack.
in any case though you need to serialize it and write it to a file
Uh, okay I'll just ask on commentaries of how I did things so far ig
Uh, might seem quite insane, but I've basically made a whole system centered on structs I named SavedObjects, they basically contain:
A prefab id
An instance id (Index at which they're registered)
An instance code (Security against a new object taking the index of a destroyed object being mistaken as the old one still existing)
A position
A rotation
An array of strings to store extra data
All SaveableObjects are backed with a SavedObject, and persistent references (To bypass the loaded object being unloaded) basically is 2 int with the instance id and the instance code
Hey guys, is it possible to toy around with Input System UI Input Module's settings?
programatically
I'd like to temporarily disable ui navigation but i am not very sure how to
Y'all see why I'm asking about how you save stuff now? I just wanna fact check if what I did isn't simply insanity ๐
seems pretty reasonable. Not sure I totally understand the difference between instance id and instance code
presumably the prefab id is so you know which prefab to instantiate
The only thing I see necessary is the prefab ID and positions rotation tbh. Strings of extra data dont really make sense, you're gonna have to parse that somehow into something
presumably each individual script would know what to do with the "extra data"
e.g. a flower script might know which type of flower had bloomed based on it
but an array of strings is quite freeform
id = which prefab
instance id = index in the global registery
instance code increases once everytime something takes over an empty registery
Basically I keep a list of SavedObjects in 1 place
And destroying one only makes that place marked as free space
so "global registry" contains all active objects and is basically a list whose slots can be recycled whereas "instance code" is a different system where ids cannot be reused?
I guess I don't see what value that has
Does the order actually matter?
SavedObjects are inactive objects, basically the data version of SaveableObjects (Which are monobehaviours, in contrast to the other being structs)
Well, you wouldn't wanna removeAt in a list of 330000 objects...
no but I wouldn't use a List
I would use a HashSet
Literally
Trying to make just 1 generic save struct for this probably wont work nicely for this. Also using structs here for such a large amount of data is probably worse than just using classes. Also consider that for the string array, you need to parse that data manually into what it is, which can basically be seen as storing json inside a json. I would really just make separate types for each thing that needs to be saved. If it derives from a single thing to ensure it implements the prefab ID then that's easy too
Structs should really just be used with small data
Anyway that's a different debate. I can see the benfit this might have at runtime but does it have any benefit in the save file? When you save and reload the game you don't care about objects that used to exist but have since stopped existing, right?
Yes, the save file itself kinda of another story
Like even if all the object IDs get shuffled when you load, that's not a problem right?
Even though the savedobject system essentially already stripped it down to what needs to be saved
Nope, it is
Since I keep them structs where references are via an instance id
And why structs, you may ask?
Uhm, I don't think that I'd know how to severe all references to a savedObject once it's destroyed if it's a class
It's a monobehaviour thing
Let's say we have:
Red Block at position 4, id 100
Blue block at position 5, id 101
Green block at position 6, id 102
If I save this as a list:
[red 4, green 5, blue 6]
It doesn't matter what order that list is in right? As long as when I reload the game there's a red block and position 4, a green block at 6, and a blue block at 5 right?
And if the new red block's id is 200 instead of 100 that's not an issue right?
It has a problem, cus if blue block references red block via his id in the list
You can't legitamately reference a struct, unless if I'm wrong
I see, so your objects are actually using this id as a reference somewhere
you're correct
Even if you can reference a struct, it'd likely become the same issue as using a class
Which basically is, if blue references red, but red gets destroyed, then blue keeps red alive via it's reference
really I would just use some kind of ID number but use a Dictionary<object id, object> to access them rather than a list
list order, as you know, is quite annoying to deal with
you can convert to a list and save the id number with the object in the save file, but use a Dictionary at runtime
they are fast for adding and removing objects too
Well, that's the funny part, I simply don't order the list, when something is added, it will look through a queue containing free indexes, and if one is destroyed, it just adds it to the queue
yeah I'm familiar with this strategy
sort of like a malloc/free thing
Yeah
It just have the issue when something takes another's space and gets regarded as the older thing at that registry
c# hashset and dictionary can be iterated over as it implements IEnumerable
I don't quite get that tbh
That's only a problem if you have orphan references to objects that are deleted
How would you circumvent that kinda issue?
I don't think there's any other choice than references being integers pointing to the index
It kinda depends. There's several options and the best one depends on the specific circumstances. You could:
- always make sure that any object referencing any other object gets notified if the thing it's referencing is destroyed, so it can forget about it
- use tombstone objects which are basically never actually destroyed (e.g. just mark it as isDestroyed = true)
Your generic object struct here could implement an OnDestroyed event that referencers can/should subscribe to for the first option.
I don't exactly see how either of those can work, in fact, I thought about the first one buuut... It's not gonna work, wanna know why?
I honestly prefer malloc over automatic* garbage collection as I prefer having errors to things for when I am supposed to have cleaned those up. I feel like it's harder to catch those dangling references otherwise
Anybody know?
If the referencer gets unloaded first, so the reference becomes merely an integer in data, and then you destroy the one being referenced
Heck, you do extra work in unity having to make sure you destroy scene objects too, so you're working over time when it comes to making sure you deload your stuff, haha
Well, to be honest me and Unity, in that project it's a bit of a love/hate situation
I have to fight unity often times, remaking systems on top of theirs to do what I want
Buuuuut not using Unity is gonna be very troublesome as well
Legit I consider what I'm doing some sort of remaking a system on top of theirs, since I essentially defined some sort of gameobject system with what I did (And I often still wish to make more control)
Which is tbh pretty weird, cus in the end you'd nearly assume Unity's system actually has all I need, but maybe hidden away in the depth of the engine
Whelp, ig that I got something out of this, first, I'm not insane nor dumb to have made this system.
Second, the only alternative possible that I avoided is that all SavedObjects are classes, and subscribe to OnDestroy events.
In which case, there's currently 330000+ objects on the surface world, soooo.... 330000 classes each with an ondestroy event......?
I am trying to dynamically make a "catalog" for the structures in my game. Ive so far instantiated all of the ui elements onto a panel and I want to change another variable depending on the button you press. My issue is that all of the buttons give me 15 instead of the current value of "i" inside of the for loop.
Any fix?
Thanks in advance
Ill try this, thanks alot!!
Can someone tell me how I should format the listener method to get rid of this error?
i'm bad with generics
your OnGrabbed method does not accept a PointerEvent parameter like the delegate expects
Damn, it was that simple. Thank you
I still often get thrown off and confused by stuff in angle brackets haha
it's not even a matter of understanding generics, it's understanding that the UnityAction with a generic type parameter will be passing an object of that type to the methods subscribed
Just like System.Action UnityAction has generic and non-generic versions where the generic versions are basically exactly the same, except they pass one or more parameters
Makes sense. Wish the error message dumbed it down a bit like "arguments requires a PointerEvent type"
It kinda does . . .
yea, yeah ๐
๐
So, is this worth it in terms of performance or is there no difference at all:
public bool CanItemFitInInventory(ItemInstance itemInstance, int amount)
{
// Yes if empty slot available
foreach (var slot in ItemSlots) { if (slot.Amount <= 0) { return true; } }
foreach (var slot in ItemSlots)
{
if (slot.Amount <= 0) continue;
if (slot.ItemInstance.Item.Id == itemInstance.Item.Id && (slot.Amount + amount) <= itemInstance.Item.StackSize)
{
return true;
}
}
return false;
}
public bool CanItemFitInInventory(ItemInstance itemInstance, int amount)
{
// Yes if empty slot available
if (ItemSlots.Any(slot => slot.Amount <= 0))
{
return true;
}
return ItemSlots.Where(slot => slot.Amount > 0).Any(slot => slot.ItemInstance.Item.Id == itemInstance.Item.Id && (slot.Amount + amount) <= itemInstance.Item.StackSize);
}
I have no idea about LINQ-expressions and dont really understand them too much but my IDE is suggesting this change by itself. Its a method that potentially can get called very often if the player stands on a pile of items so performance would be important here. Not sure if there is any difference between these though? I assume that if the IDE can change these by itself then so would the compiler into the most efficient one.
In this case I'd imagine no difference. If you're concerned about performance though, iterating the collection twice should be the flashing alarm bell here
LINQ allocates, GC pauses might be a bigger concern.
Hey folks -- I need a quick sanity check. This operation should do nothing, right? Do I have the order correct here?
newAverageRotation = newAverageRotation * Quaternion.Inverse(x);
newAverageRotation = newAverageRotation * x;
(newAverageRotation is a quaternion)
It should do nothing, subject to the limits of floating point precision.
What you've got here is basically:
a = a - x;
a = a + x;```
Thanks, that's what I thought. I can't imagine I'm running into precision issues, but maybe. Something funky is going on.
is the result REALLY off
or just like
slightly off
I would expect you to have a small amount of error for basically any value here due to precision errors
it's slightly off at first, but then it compounds a few times and gets ENORMOUSLY off very fast
how many times are you doing this calculation
like once per frame or something?
the errors could compound pretty quickly
yeah this is an editor script, so once per scene update
Could you show the real code here? I imagine the real operation is some more complex thing
sure, one sec
And maybe there's a better way to do this
For example - just storing the original rotation and restoring it afterwards
so, this is the end result of a lot of debugging: basically, I'm trying to implement some rotation handles in this editor, but in order to do that with multi-select I need to get the difference in rotation and apply it to each selected "viewpoint." for simplicity I've worked out this, which is the simplest thing I can do that still creates the problem. for this example, I'm just applying the rotation to a single viewpoint to see if I can get that to work.
EditorGUI.BeginChangeCheck();
Quaternion newAverageRotation = Handles.RotationHandle(firstSelectedViewpoint.localRotation, averageSelectedPosition);
if (EditorGUI.EndChangeCheck()) {
Quaternion rotationOffset = newAverageRotation * Quaternion.Inverse(firstSelectedViewpoint.localRotation);
firstSelectedViewpoint.localRotation = firstSelectedViewpoint.localRotation * rotationOffset;
Debug.Log(firstSelectedViewpoint.localRotation);
}
If I set the rotation of the viewpoint to the handle output directly, it works fine
Here's the log output when I start rotating the handle in the editor:
obviously a quaternion shouldn't look like that!
@leaden ice pinging just to make sure you saw this
right so this minimum example proves that our problem is due to floating point precision errors right?
yeah it must be, right? I'm not sure how to fix that, though. normalizing the offset quaternion causes other problems
wait isn't thois wrong?
Quaternion rotationOffset = newAverageRotation * Quaternion.Inverse(firstSelectedViewpoint.localRotation);```
is it? what am I missing
maybe i just have to handle this in a different way. storing vectors or something instead of quaternions. cause this is wild
What's the goal here? You're trying to get the rotation diff so you can apply it to a bunuch of different objects?
Yep exactly
silly question but like
what happens if you use world space rotations
instead of local
yeah that is a good idea but these are actually worldspace
no parents?
i just didn't want to rename my variable just for debugging haha. these aren't transforms, just a barebones class that holds a position and rotation
Actually wait it may be this
Quaternion rotationOffset = Quaternion.Inverse(firstSelectedViewpoint.localRotation) * newAverageRotation;```
order of operations does matter here
I'll give that a shot
My napkin algebra gives them in that order:
newRot = fsv + diff
newRot - diff = fsv
-diff = fsv - newRot
diff = -fsv + newRot```
But I'm not sure if I did the algebra right given the non-commutability of + here
huhhhh still broken.
Oh wait a second
okay if I do that AND normalize the diff that seems to work!
awesome!
phew! Thanks so much!
Do we need to manually integrate quantities in our code, or is there a way to piggyback off the integrator Unity uses for physics?
in what context?
E.g. applying gravity to a Character controller
The way the physics engine integrates is to just use a fixed timestep
No this is not completely physically accurate, and that's ok
Yeah, but I assume the physics engine isn't doing explicit Euler the way the sample assets player script does it
it's pretty much just doing this every fixed timestep
velocity += Time.fixedDeltaTime * gravity;
position += Time.fixedDeltaTime * velocity;```
You can verify this yourself
I thought the physics engine was in the C++ core of the engine?
And not open source?
Ah
Ah, ok, so it's not actually doing this, it's doing
position += Time.fixedDeltaTime * velocity;
velocity += Time.fixedDeltaTime * gravity;
But yeah, it's just semi-implicit Euler
... Wait
No
Damn, my numerical analysis is rusty
No, you were right, it's velocity first then position
Well. Huh, I was expecting some higher order integrator
Iโm trying to make a instantiated object shopt forward and when i set the velocity to vector2(1,0) it moves but when i set it to transform.forward it stays still, anyone know what the issue could be
I'm guessing 2d?
The forward of an object in 2d by default would be the z axis.
You'd probably want to move relative to the object's right (assuming this is 2d)
Sorry to disappoint you my dear
anyone knows why input field doesnt work on mobile? The keyboard doesnt pop up to allow me to type
The textmeshpro one ?
yea
Please just be patient
No itโs not an issue. Not sure what it is then , try googling to see if you need to force keyboard idk I recall it works for me out the box
How are testing mobile exactly?
I put the game on itch.io
Is it apk or webgl?
WEBGL
is there a workaround?
like how can I implement a game without it breaking like that on mobile?
cuz I was also thinking about adding a virtual keyboard
that explains it
Anyone got any wise tips on how to achieve a tidal lock?
the Moon is tidally locked to the Earth because it rotates in exactly the same time as it takes to orbit the Earth.
I would preferably like to be able to tick a bool which would take into account the moons orbit Speed and distance from planet to moon to always have rotation locked regardless of its speed or distance!
you can try the old Input or maybe UIToolkit has support out the box for that
oh ty
private IEnumerator RotateAroundPlanet()
{
while (true)
{
if (planet != null)
{
float angle = 0f;
float rotationAngle = 0f;
while (angle < 360f)
{
// Calculate the position of the moon around the planet
Vector3 orbitPosition = planet.transform.position + Quaternion.Euler(0, 0, angle) * new Vector3(moonData.orbitRadius, 0, 0);
// Set the moon's position to the calculated orbit position
transform.position = orbitPosition;
// Increment angle based on orbit speed
angle += moonData.orbitSpeed * Time.deltaTime;
// Rotate the moon around its own axis
if (!moonData.isTidalLocked)
{
// If not tidal locked, rotate at the specified rotation speed
rotationAngle += moonData.rotationSpeed * Time.deltaTime;
}
else
{
// If tidal locked, calculate rotation speed based on orbit speed
float orbitalPeriod = 360f / moonData.orbitSpeed; // Time for one orbit
float rotationSpeed = 360f / orbitalPeriod; // Rotation speed for tidal locking
rotationAngle += rotationSpeed * Time.deltaTime;
}
// Apply rotation
transform.rotation = Quaternion.Euler(0, 0, rotationAngle);
yield return null;
}
}
yield return null;
}
}
Nevermind i got it working , heres the coroutine if anyone is interested in it
// Apply rotation
transform.rotation
nice comments
i use chat gpt to help with alot of things!
find it easier to use it as an assistant rather than just making it do everything!
lol im not saying make it code everything lol
comments really shouldn't be just stating the obvious though, making that Apply rotation comment pretty useless
forsure , that was def chat gpt
and that's one of the many reasons to not use it
lol gotta learn somewhere!
makes my life easier , no need for me to add comments or completely restructure something simple when it can do it for me
in the end it still needs human input to be useful
You can learn many many places. Chat gpt is not even close to being on the list of places to learn
It will actively hold you back, lie to you, hallucinate, and teach you very bad habits
It could be argued to be ok when you have already learned to tell when it is wrong (i would argue the opposite), but it is HORRIFICALLY BAD for beginners
i am self taught using tutorials and chat gpt over 2 years, Give me a quiz if you think it has been bad to me im always eager to learn or be corrected!
And yes you are absolutely right it hallucinates alottttt , i cant tell you how many time it has just made up non existent using statements.
Imagine this, you may have knowledge now, and that is good, but you could have learned faster if you had not been held back by the spam generator
without it i would have never gotten started!
i can code myself!
Well that is terrifying
lol i mean i never had an interest before hand
the ease of being able to have it explain things to me when i ask is amazing
there's a surprising number of people that have a real burning hatred for AI - I think it's very evidently a great learning tool though, respect for getting things out of it
i understand the hatred for it!
I dont like the thought of something being purely AI but if you are able to input your creativity into it and brainstorm with it i think it can be really good!
The "hatred" is mostly born from the constant flood of garbage people get from it that they expect us to fix here
Spend enough time teaching and helping and you will see it
i can see that!
There is a reason it is against the rules to use it for helping people or to ask for help with code from it
as opposed to everyone else that always reads the obvious google results and documentation, right? ๐
lol i can see if the code hasnt been vetted by the user first
its not hatred , I could care less what other people do its when the code breaks or isn't a real functional script, people come here to ask for help , which is a waste of time of everyone involved since they also have no clue what you're explaining to them cause they used GPT for everything
Unironically yes. Because at least that is close. Unlike 99.9% of the code from gippity brought here i misunderstood you. Missed the sarcasm. Yes, people skip docs sometimes. At least THEY are trying. Which is not true of the ones using gpt
lol it should just be a pinned message that you are not allowed to post questions related to chat gpt if it needs over 3 references!
its okay with simple things , trying to get it to implement XOR encryption or A* is just not gonna happen
there's definitely some knee-jerk and unfounded hate for it, see it all the time, people are absolutely frothing at the mouth to insult or downplay how helpful AI can be in figuring out concepts or learning something new, or just as a starting point to give you some keywords to investigate further
it's utterly bizarre how much some people want to hate everything about it - not sure if it's fear or insecurity or what
I haven't seen that. That's quite sensationalist
I just think it is realism
yeah dont think ive seen any forthing at the mount hate for it
And frustration over people suggesting it to beginners, who it WILL harm
especially if you use it correctly!
ask it hey what's an interface or what does abstract mean , goes a huge way
nothing google can't answer though..
and more accurate because you learn critical thinking skills
See, that is the exact worst way to use it. It will often give a good sounding but fundamentally incorrect response
So many good examples on google
rather than being sure the Spam generator is being legit
forsure but i can talk to it like a person... maybe i dont understand a key point of it
cause thats really what its meant for.. fake "human-like" interaction
the problem is that most people don't use it that way. rather than using it as a supplement to help them understand concepts that they have been introduced to or as a tool to figure out what they should be learning, they use it as the primary source of learning. so they learn incorrect things because the AI doesn't know anything. it's just a very advanced text predictor like your phone's keyboard has
Also when people ask for help and someone rolls in and says "i dunno, ask gpt"
Like, if you don't want to help, then don't help
We are here, and willing. No need to send people away
I'm not sure that's actually true at all, I think that's a perception people have to "other" people who use it, and ultimately to undermine it itself. I understand why it's frustrating to try to help someone who hasn't engaged with a problem they want to solve, but it's little different from the countless other people that ask questions who didn't even bother to google it or look at the unity documentation
It is definitely true
Hell yeah it is different ๐คฃ
Edit: maybe that's my "frothing hatred" though lol
The issue is the way you use it. You can also google "complete script that does x" and when it doesn't work copy paste it in discord and ask why it doesn't work without any understanding of the code.
It's just easier to do such a thing with ai
it absolutely is true. i don't think you understand just how many times people have come in here trying to get help with AI generated code because they don't understand the code that was given to them and it doesn't work the way they expect. and there are a number of reasons that happens, mostly because people make the assumption that the AI somehow understands anything and expects it to be a good resource to learn from.
it's not. like i said before, it's basically just an advanced text predictor. literally all it is doing is predicting what the next most likely text would be based on its training input. this makes it a terrible tool to learn from, and the best it can be used for is to basically just rephrase other information in a way that (hopefully) makes sense to the people using it, but quite often, especially when it comes to unity stuff, it just makes things up. and then someone who doesn't actually understand the concepts they are trying to learn ends up internalizing that made up info or they come running to here because they heard they need to do something a certain way.
using text generators as a learning supplement is okay provided you already know what you are doing. but of course to already know what you are doing you need to learn from a decent source
You can't possibly know how many people have used ChatGPT in some capacity and have used it to springboard their ideas or solutions, that have then come and asked questions here though. You're only basing that perception off of the egregious cases that make it obvious they have fully relied on ChatGPT and haven't engaged with the problem themselves
Well, as long as they can show understanding and effort, it's fine if they use ai.
I can see the frustration of the new people expecting god like answers out of spaghetti
I used to mod battlefield V and trying to help people swap meshes was exactly like that
No one blames them for using ai specifically. We blame them for using it to cut corners. Important corners.
you cant even ask questions unless you understand the basics
I agree, but that's not the balanced take a few people here are trying to push at all
Where?
That seems exactly like what boxfriend and I are saying at least
Just that it isn't the norm that we see
it's only a balanced take if you agree with them
I agree that this community is a bit biased against ai based on my experience. But there's nothing you can do about it. And there's no point arguing about it.
i think we all have a deep hatred for machines
That's the thing - you see a bunch of people that are using AI in an unproductive way, and you've made the leap to saying most people/99.9% of people are wasting everyones time, learning incorrectly, AI bad, etc, etc
Someone could come in here and ask a simple question and get a load of useful help. A different person could come in and ask the same question, but also mention they tried to ask ChatGPT first, and they'll get 5 people jumping down their throat like clockwork over how useless AI is and how it should never be used
but it's whatever, you do you I guess
This is again sensationalist take that is not what is being said. You have this strange desire to twist things into a way more sinister/hard way than they are. Please do not put words in my mouth
I NEVER said that
I am saying there are better and faster ways to learn. And I truly believe that.
It is also a server rule to not use gpt code for help or questions
And I disagree about the part at the end. I see people mention it all the time and get help just fine
as long as they aren't asking for help correcting THAT code, which is against the rules. Which if they are, yeah, people point that out
I should say that I am on every day and scroll back to see what I missed, so maybe I just see the balance more?
don't forget how this conversation started - a guy asked for help, and then showed that ChatGPT was able to help him arrive at a solution to his question, shortly followed by the lectures on how useless AI is and how it should never be used ๐
I strongly disagree with that analysis of what happened
It seems like maybe that's just the way you want to see it?
I mean you can literally scroll up and read it if you like
it's still there
good talk though, I think this conversation has run its course
They said they resolved it before anyone said anything
And THEY brought up gpt, and people just had a good chat. Mostly until you came and started making it hostile.
Hellfire was doing great and we were just having a friendly discussion, but you called it "frothing hatred" lmfao
But yeah, I'm done
Yeah, this is not a case of help refusal simply due to them mentioning ai.
@fickle moth
One last thing I DO want to say. Deynai obviously misunderstood the tone of what was being said at the beginning. I want to make sure you didn't feel that way too.
In my opinion, you have clearly been putting in the effort, you even resolved your issue before anyone could respond.
Don't want you to feel pushed away or put down. My comments in the beginning were true to how I feel, but also tongue-in-cheek. I thought that was clear, but clearly not haha.
Anyways. Apologies if you felt insulted or anything. Please do feel comfortable coming back for help whenever you need
Never felt criticized at all!
I understand how it is! and i appreciate all feedback!
appreciate you for the kind words!
Awesome. Glad that is the case!
I do
"Some men just want to watch the world burn"
Every time some company sends me a survey about their AI products I spend half an hour writing out all the reasons. They keep sending me surveys!
That might be why!
they know you will fill them out!
print them out and use as toilet paper
Some poor engineer collecting reasons to get back to implementing something solid instead of massaging a pile of statistics until it blurts out the right thing
How should I approach plane physics. Someone told me the current way Im doing things is just reinventing the wheels and such. The hiearchy of my plane is an empty gameobject, with plane parts as the children. In this scenario, Im working on implementing a thruster, yet is the thruster is asymmetrical to the plane, torque would make it rotate. How can I, through code (the script is placed on the empty parent), place a force at the position of the thruster, and have torque apply, rather than the whole plane moving perfectly forward when asymetrically placed.
Does that have torque physics built into it
did you bother reading the page?
*guess I can just cl-
was boutta say that lol
ah, literally the first line
If .AddForceAtPosition has torque built into it, then what the point of having a .Torque function in the first place
because they do different things? AddTorque adds only torque to the rigidbody. AddForceAtPosition adds a force at a specified position which also results in torque being applied because the force is not being applied directly in the center of the rb
aight
ive not done source gen before in c# is it possible to use source generation so i can create enums on the fly in custom editors ?
im using strings at the moment but not a fan of it
it's a bit awkward to set up but rosyln source generators are supported, there's also CodeDom available in editor if you just want a better way of generating a source file yourself
how would my ide know ive created these enums so i can use them in code without errors of undefined all over the place though
IDE knows how source generator works, they can read the generated code.
But from this question, I would say source generator is not the right tool for the job.
The best use case of source generator is to "use existing code to generate more code," but it sounds like you want to generate code from assets/editor actions, so it's better to just use a regular editor script that creates and writes to .cs files.
we can edit cs files from editor?
because i need the bit flags of enums which strings dont provide but i need to be able to add / remove enums
but typically enums are hard coded
It's just files, you can write to them like you would with any other files.
i see
Hi there, i have added this models of a mannequin, and i wanted to add a feature to them but idk how i do it, i wanted to them to make a random audio, but only when i am a little far away, if i am to close then them don't make any sound, but if i am far from them, it would make a random audio.
Does anyone know how to add that feature?
Do you guys get angry if I say that I program my game with AI? Lmao
Angry? No.
Point out that it's against server rules to ask for help with AI generated code? Yes.
I couldn't care less, unless you'd come with AI generated code, not understanding what any of it does, and asked us to fix it.
Ahhh like that. My issue is, I suck at programming, did try many times. I know how to build the code technically and how methods should communicate etc, I'm just a total 0 IQ when it comes to remembering it etc.
I make up the methods and what they should do and contain and all that. How different methods or even scripts communicate with eachother. I just need help getting the actual code down
Well, try harder, there's nothing else you can really do. Using AI generated code will just hold you back even more, and with enough practice you'll eventually be good enough to not suck at it
Practice, practice and once again practice
Maybe one day
I hate to be blunt. Either stop sucking at programming or give up, there is no third option
Ayy, time to stop in that case eh
You get better at programming by doing, keep doing.. more and more, do different things, etc
You're not expected to remember everything, even experienced devs google simple things because they've not used it in ages and have forgotten
yeah, the sign of getting better at programming is being able to find and use more info, not being able to memorize more code
I would beg to differ. To use an analogy...
Most people can learn to read and write. That does not give them the ability to become a novelist.
hey, ive read some terrible books before
and some of the best games have terrible code style, lol
yet you'd still consider those who wrote them novelist
What's the fix for unity packages/libraries not being recognized by VS? I've tried regenerating csproj files, deleting Library, restarting VS, restarting Unity
No errors from within Unity it's just a VS issue. Other usings not recognized are:
UnityEngine.UI
NaughtyAttributes
Do you use assembly definitions?
Not as far as I know but it's not my project. What could the issue be if I was?
IF you have those you'd have to reference Cinemachine in your assembly definition since it doesn't recognise it otherwise
Ok I don't think that's the issue afaik
screenshot your package manage window with 'In Project' selected
I think that must be the issue, can you screenshot the project folder where the CameraManager script is
The reason I don't think it's the issue is that Unity doesn't complain and compiles fine. Also other people on the project don't seem to have this issue although they are using different IDEs I think
Then you may need to ReGen your projects
Right now I'm updating VS in case that forces something to fix itself. After that I'll try deleting the .sln file and see if that does something
Or just Edit->Preferences->External Tools->Regenerate project files
Yeah I've pressed that a good few times
which IDE ?
which Unity version?
Ok, but for those who can program.. learn by doing.
2021.3.11f1
I think you should install at least VS 2019
I have VS 2022 sorry should have mentioned that
can you screenshot your external tools window
Ah, turn off all the checkboxes except Embedded packages and Regenerate
you might want to delete the .sln and all of the .csproj file before doing this
Ah that worked thanks! Do you know why you have to uncheck the other boxes?
because Unity is absolutely crap at generating working .csproj files
Brilliant thanks lol
hi someone have some experience with assetsBundle ? i'm trying to download a scene and the materials are all purple and missing , the BuildTarget is Webgl and my build is in android is that the problem?
Is there any way to know when a particle system is done emitting ?
Hello guys, i have a small problem about repainting a property,
i a using a custom editor to draw a property, but the repaint is doing only if I move my mouse.
i have try InternalEditorUtility.RepaintAllViews(); but this is using too much performance (5 fps)...
do you have a solution to repaint my property every 0.5sec, so i keep my fps ?
thanks you
I make a duplicate of a 3d object, scale it up 10-20 percent, and i need to make sure, that the Y pivots are at the same point. I.e. the Y scale is bigger the same amount on top and on bottom
Programmatically or just in the editor?
Ohhh so the origin isnโt actually the middle?
just transform.scale ?
Yeah, the character 3d models im using are kinda f'ed up
never in the actual middle
I was thinking that but if the origin is a bit below centre itโll scale more upwards than downwards is what theyโre getting at
So the original pivot is not center ?
Mhm
could make parent object and scale that after offsetting child properly
or just fix the pivot in blender first
there's 30+ objects, I really dont wanna do that in blender ๐
Arguably the more sensible choice yeah
So you basically want to 'scale around a point'?
Do you know the size of them before being resized? If so the maths shouldnโt be too hard to work out, idk how fucked up your objects are though lol
I actually made it work with the same scale, it looks even better what i was doing, but now i'm kinda interested on what would be the solution
Nope, i tried with Renderer.Bounds.size, but couldnt get reliable results
Yup, I made a shader that glows around the edges of the mesh, and wanted to make the object with shader be a bit bigger than the original object
I think thatโs easier at the shader level tbh
In that case you could try vertex displacement in the shader
Unless it has hard edges, then it will look off
What I mean is basically adding normal * someScalar to the vertex position
I'll try that, im kinda new to shaders. The objects do have a lot of hard edges
How does a normal work on a vertex? Is it an average of the faces around it?
I think it's interpolated from 3 vertices of the triangle
EDIT: Yeah
But yeah hard edges are probably an issue here. They are actually separate faces in unity so it would leave some gaps
It could be that but you can actually make it whatever you'd like.
Stop trying to use System.Text.Json unless you install it as a DLL in Unity
Do i use Newtonsoft json thing?
Hello
Im want to make my raycast bigger , i saw that Spherecast is the way to do it
`void LateUpdate()
{
// Check if we are grounded now.
bool isGroundedNow = Physics.Raycast(RaycastOrigin, Vector3.down, distanceThreshold * 2);
// Call event if we were in the air and we are now touching the ground.
if (isGroundedNow && !isGrounded)
{
Grounded?.Invoke();
}
// Update isGrounded.
isGrounded = isGroundedNow;
}`
What do i change here?
Didn't you answer your own question? Use Spherecast instead of Raycast
Well the problem is , my character (or the fps controller) cant jump when on the edge of an object, basicaly gets stuck on the edge. I know this is a common problem and i think i can fix mine if i just make the raycast bigger
How tho
Wdym
Get used to looking up the documentation for any function you're not familiar with. That's how the rest of us do it. That's what documentation is for.
type debugging your json string. I bet it's empty
wait yeah
but i have the object and jsonutility thing
so what is it classes need to be before you can serialize them?
huh?
you don't know what you are doing do you?
i mean its my first time using json
ok, you are trying to serialize your object using json. In order for a class to be serialized is need to be marked as Serializable
yep
I alr had the serilaoziable thing
not according to this #archived-code-general message
ok, and where are you expecting the file to be?
ok, next lesson. JsonUtility does not serialize properties
do i have any?
uh yea
what do you think these are? #archived-code-general message
oh mb โ ๏ธ
i mean i was just following the unity documentation
and thats what they had
where
those are fields tho
hugee difference (exaggeration)
where do you see they added get and set accessors

which API Compatability level shoudl I be using in the "latest" unity? (I'm on 2022.3*). The docs are really confusing. This page says to "use the .NET Standard" compatibility level, but that is not an option in my Unity. I only see two options, ".NET Framework" and ".NET Standard 2.1". Am I to assume that what they are referring to is the ".NET Standard 2.1"?
And what exactly then is ".NET Framework"? that's also not described in the help pages
Yes .NET Standard 2.1 is .NET Standard
Not sure if this goes here or not, but I have a piece of code for my interaction layers and thereโs a bug in it, I just canโt figure out where. For some reason, for only some of the layers, when I click to activate that layer, it also activates a layer at towards to top of the list as well. I can show screenshots of what that looks like as well as what the code looks like
Code is too long to send here
This is the error tho
Left foot phalanges later and default layer activate, and thatโs not what I want to happen. I want it to be only left foot phalanges
!code
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Can also be viewed here
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Please ping me if youโre able to help out, thank you
yo how do i import mesh from blender with animations and camera shake that i made in blender ?
Possibly this works?https://www.youtube.com/watch?v=3CSUxATQVLw&ab_channel=GabrielAguiarProd.
Unity Tutorial - Importing Animations From Blender / Blender to Unity
In this unity tutorial number seventeen of the Lost in the Sea series, we import animations from blender to Unity. This includes importing the animations we created of the Octopus to Unity.
From Blender to Unity import animations correctly and fix problems with location, rot...
Why can I not use await with LoadSceneAsync?
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static async void Init()
{
DontDestroyOnLoad(Instantiate(Resources.Load("Systems")));
await SceneManager.LoadSceneAsync(0, LoadSceneMode.Single);
}```
Here is the error
AsyncOperation' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'AsyncOperation' could be found (are you missing a using directive or an assembly reference?)
AsyncOperation isn't the same as Task
its meant for coroutines
https://docs.unity3d.com/ScriptReference/AsyncOperation.html
damn ok, what would you do here then?
this is to load a Bootstrapper as default scene
did you see the example ?
https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html
just had a look will get to it, thanks
might want to make Init start the coroutine instead of itself being the coroutine
look into UniRX, it's really nice for this stuff
I seem to have stumbled on something like that
use UniTask too
#if UNITY_EDITOR
DestroyImmediate(gameObject);
#elif UNITY_RUNTIME
Destroy(gameObject);
#endif
why cant unity determine the difference for us so we don't have to keep writing this every where -_-
Encapsulate the statements in a method and call the method - code reuse.
i have just think unity should've done it from the start
Technically, this is wrong too. UNITY_EDITOR could be play mode as well. And you don't want to have different behavior between play mode and build.
so whats the correct solution ?
is this editor script?
if not, any reason why you need destroyimmediate?
well it can be destroyed at run time by a user but i also have an editor script that deletes them
ah, that makes sense now
yeah but if unity editor is still possible at run time thats not good
although maybe you should have separate script between editor script and runtime script
ah okay thanks
The reason why you need it is because unity doesn't know if it's play mode or not when it executes you're line of code. That's why it's your responsibility to make that check.
so what does the if unity_editor even mean compared to unity_runtime?
ive seen a lot of people use if defs i guess they don't even realise it either
No clue what unity_runtime is. Can't find it in Google either. It probably doesn't exist at all.
As for the editor define it's to distinguish builds from the editor.
For example, you don't want editor code to be included in a build, so you'd use the editor define.
ah i see
does seem _runtime is not defined or not documented
would it normally not compile if its not defined
or just never occur
yeah the point of a conditional compilation symbol is to only compile code when that symbol is defined. if it is not defined, then the check returns false so it does not compile that code
It would just ignore the code inside as the condition would be evaluated as 0/false.
ah okay fair enough, i think i figured out a new work around ill have the editor script call the destroy immediate then clean up in OnDestroy, rather than call a delete function on the object im trying to delete
I cant find the read input for some reason
long is not a supported parameter type for UnityEvent
if you want to see what types are supported for UnityEvents you can check this: https://unity.huh.how/unity-events/method-requirements
I'm trying to implement individual post processing for multiple cinemachine cameras but for some reason the volume profiles always seem to be connected somehow. Even if I create new volume profiles for each camera at runtime whenever I change a value on one volume component it always changes the post processing of both cameras. What could be happening here?
private void Awake()
{
m_cameraFreeLook = GetComponent<CinemachineFreeLook>();
m_cameraPostProcessingVolume = GetComponent<CinemachineVolumeSettings>();
CloneProfile();
m_cameraPostProcessingVolume.m_Profile.TryGet(out m_vignette);
m_cameraPostProcessingVolume.m_Profile.TryGet(out m_bloom);
m_cameraPostProcessingVolume.m_Profile.TryGet(out m_chromaticAberration);
}
void CloneProfile()
{
VolumeProfile clonedProfile = Instantiate(m_cameraPostProcessingVolume.m_Profile);
for (int i = 0; i < clonedProfile.components.Count; i++)
{
clonedProfile.components[i] = Instantiate(clonedProfile.components[i]);
}
m_cameraPostProcessingVolume.m_Profile = clonedProfile;
}```
Hello, I am also making a puzzle game, and I have about 25 levels, however I can not find the perfect way to save the level on which the player is so that when he presses play he goes to that level, can anyone please help me?
You can save/persist in a number of ways, the simplest approach for something like that would be to use PlayerPrefs but personally I would look into saving/loading via JSON
I'm not entirely sure, but you could possibly just do this:
public void SaveProgress()
{
int activeSceneIndex = SceneManager.GetActiveScene().buildIndex;
// Save either via PlayerPrefs or JSON if there is more data
}
public void LoadProgress() // Call when pressing Play
{
int sceneToLoadIndex = // Load either via PP or JSON
SceneManager.LoadScene(sceneToLoadIndex);
}```
How can I make a callback in 1 line without creating delegates?
I.e. I want to pass callback into a function.
In my case a Transition effect is supposed to call a function after its finished(my callback function)
Transition.Instance.FadeIn(() => DoThis());
Does DoThis have any parameters? If not, you can just .FadeIn(DoThis).
Are you implementing FadeIn and you are asking about what type the parameter should be?
yeah
That would be Action.
Thanks
Unity is refusing to acknowledge collision and I am about to fail a class because of it
Are they both on same Z axis(not sure if that matters for 2D games, but I assume it might)
What about 2d matrix?
Is any one of them set to "IsTrigger"?
no
Then show some code
Do they have rigidbodies?
I am pretty sure rigidbody2d is required
If its 2d game, then you should use colliders2D + rigidbody2D
they do
Not sure what is sleeping mode in rigidbody, but check if its not "start asleep"
this is not 20 questions, screenshot the inspectors of both objects and show your !code
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
the top one is not working
well you have obviously done no debugging whatsoever
I have no idea how to do any of this I am trying to not get an F in a class that ends in 56 minutes
I don't give a rat's ass about debugging I want to pass
then you deserve an F if not lower
in my day it was U - Unclasified
That's not what I said
Tbh even if it doesnt work, I assume you'd get more than an F for trying?
nah
Then you better start learning how to debug issues fast.
If they taught you basics of debugging then this should be few minutes of going through code step by step in debug mode.
I don't even know how debug mode would be activated
I can assume that your objects dont have proper tags so your script is not detecting them.
Also OnCollisionEnter2D should be on a weapon or an enemy, so I dont know why you'd check for tag weapon and name of enemy.
I could be wrong tho.
I provided you with a link.
you ain't gonna even come close to passing if you don't start to 'give a rats arse' and damn quick
Yeah tbh why do I care more than he does, good luck ๐
I would love to learn something that takes months in 20 minutes I really would however that is not possible
it doesn't take months, it takes 5 minutes
and you still have not provided the requested screenshots
You marked your collider as a trigger
So this was a lie
Yeah we can't blame Unity for this one
it was changed as troubleshooting ie it was already not working
<@&502884371011731486> these people are being incredibly condesending
Do you want the mods to castigate us or didn't you have a class you were about to fail in 34 minutes?
What would you like me to do for you, here?
Back in my day we didnโt have access to discord during our finals
Tbh for his use case, he needs a trigger I think ๐
Back in your day people were decent. I guess you aren't like your generation then.
You would not have to if you just start your project on time unlike this guy
Bugfixing is one thing, but having to make your game even playable in general an hour before the deadline just reeks of improper planning
Iโm 20, if you paid any attention in class you would de-facto not have this issue. We refuse to help you pass class if you couldnโt learn the basics. Come back after the finals when youโre willing to learn.
Issue is solved, everyone can go about their day now.
Nobody asked
@high trail If you don't have a Unity related question don't post off-topic here
Wow.
In their defence they did
Just entitlement from the start and you wonder why you're getting this response
And they are preoccupied with bickering instead
Well, only 20 more minutes before their supposed class ends. Good luck to them. ๐
Yeah let them bicker for 25m longer and maybe theyโll take the hint from an F
I have a general code question about booleans.
I have a Transition screen script and I store few booleans:
public bool isFadingIn { get; private set; }
public bool isFadingOut { get; private set; }
public bool isFadedIn { get; private set; }
public bool isFading { get { return isFadingIn || isFadingOut; } }
That 3rd boolean "isFadedIn" is a state between fadedIn and fadedOut which means that screen is black.
I use this state to change a scene.
Should I just use enums for a state?
i.e.
public enum
{
None, // After faded out it goes back to this initial state
FadingIn,// progressing through fading in
FadedIn, // finished fading in
FadingOut, // progressthrough through fading out
FadedOut, // Finished fading out
}
Have you tried debugging?
I'd still keep isFading probably
This is not a question that debugging could solve.
Excuses
!mute 428784312834326529 24h come back tomorrow without wasting other's time
pk_spartan was muted.

Sometimes I do feel like programmers gatekeep
And other times people learn to code mid-final
Yes, I would use enums in this case
Generally a "state" would be determined with an enum because you can easily check a single property rather than multiple. You can also easily handle an order if it matters, since an enum is a number.
Actually I just realized...in my script I don't always move from fadeIn to fadeOut
for example, I can fadeIn(screen is black) then do nothing until my other script decides to fadeOut
so a state would have to know when to wait.
https://paste.ofcode.org/SvtKpTR5dxd6uvqz2jXqwR
Wall of code, anything that could improve it?
its just changing alpha lol
Use a site, please
!code
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Posted a link instead, for something so basic like changing alpha you'd expect less code right? ๐
I can probably move a variable for tempColor outside the if statement
Personally these are the types of stuffs that work really well if you wrap them in async/await.
And/or using a tweening library
I havent gotten to tweening library yet, but I have it bought for my personal project so I will start using it soon ๐
DOTween has extensions for it all
Once you have them wrapped up, usage becomes extremely simple:
async UniTask TransitionToNextLevel()
{
await FadeIn();
await LoadNextLevelOrSomething();
await FadeOut();
}
And if you want to start loading right away without waiting for fade in so that the loading time is shorter for the player? Also easy to express:
async UniTask TransitionToNextLevel()
{
// Loading starts right away in the background
var task = LoadNextLevelOrSomething();
await FadeIn();
await task; // Make sure loading finishes by this point
await FadeOut();
}
you'd just do myImage.DOColour(); and the 2 or 3 params it needs
oh I like that
How do you make sure that loading is finished tho?
scene loading I mean
Because you await it, so it must finish before moving to the next line of code.
public class Fade : MonoBehaviour
{
public enum States
{
FadingIn,// progressing through fading in
FadedIn, // finished fading in
FadingOut, // progressthrough through fading out
FadedOut, // Finished fading out
}
private Dictionary<States, Action> stateDict;
private States currentState;
private void Start()
{
stateDict = new()
{
{States.FadingIn, () => FadingIn()},
{States.FadedIn, () => FadedIn()},
{States.FadingOut, () => FadingOut()},
{States.FadedOut, () => FadedOut()},
};
}
public void Update()
{
stateDict[currentState].Invoke();
}
private void FadingIn() { }
private void FadedIn() { }
private void FadingOut() { }
private void FadedOut() { }
}```
that's my idea
I never worked with await, so I'd have to check
That looks clean
just having a general fading tween sounds good
Note that their example uses UniTask
Which is async/await but with coroutine-like functionality (afaik)
why not an Array instead of the Dictionary then use the Enum as the index?
oh UniTask is not built in Unity
You don't need to use a dictionary, you can just use pattern matching.
is there difference between a switch and pattern matching
So in this example you need to make currentState public? Since I usually want a control over it.
Specifically I want to only do FadeIn sometimes, then I do fadeOut on OnSceneLoad
ide always recommends me to change them into a pattern matching state
private void OnSceneLoad(Scene arg0, LoadSceneMode arg1)
{
if (TransitionScreen.Instance.isFadedIn) TransitionScreen.Instance.FadeOut();
}
I check if the screen is black then I fade out on scene load
Well, it's just a simplified switch, which cannot be used when the block has more than 1 line.
Is that await idea possible without installing packages?
So you can always make a normal switch out of the short one, but not otherwise
Generally not really, except that switch statement has statement semantics, and switch expression is, well, expression.
so I can do:
await FadeIn();
await ChangeScene();
await FadeOut();//after new scene is loaded
Does code run during scene switch? Should I do async scene load(I think there is such a thing, but it might have a different use case?)
yes, Awaitable is available in unity 2023 and does the same thing, otherwise you can just use plain old System.Threading.Tasks.Task for that case, it's just not as efficient in some ways
async/await is built into C# as well.
IEnumerator LoadYourAsyncScene()
{
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("Scene2");
// Wait until the asynchronous scene fully loads
while (!asyncLoad.isDone)
{
yield return null;
}
}
Seems like something I might want to use for my case?
Enumerator based coroutine is basically a caveman version of async/await.
Theres no way to sync up with the Unity game loop though, right?
Such as waiting for a frame
But your example uses UniTask which seems to not be part of Unity?
Correct, which is what UniTask gives you.
it functions nearly identically, it's really down to which one suits your code better... like often loading scenes you don't want to run a coroutine on an object, because your objects are going away with your old scene haha
Indeed. They were asking about byiltin ways
you don't need any third party code to wait a frame
Task.Yield works fine for that
Is UniTask in asset store? I only found some github page and I am not a fan of installing packages outside of Unity or in general as I will have to remember it for all of my projects if I want to keep using it.
git
if you want to go vanilla only, regular c# async/await is totally fine, UniTask just has some convenience features and allocates a little less
I was under the impression that Task.Yield is not guaranteed to wait just one frame
try it and see!
the unity sync context updates once per frame like coroutines do
i believe some time between Update and LateUpdate
Any recommended (game related) examples of async/await to learn from?
I never use those nor do I use IEnumerator in my games and I am probably losing on a lot.
I used a bit of those in the past, but it didnt stick with me.
there's some examples in the unity docs https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Awaitable.html
Oh TIL, that's cool.
Is there any situtation where there would be a difference between Component.name and Component.gameObject.name ?
no
If not, which one is faster / better practice ?
they are the same
Besides Unity specific stuffs, you can also learn about async/await in regular C#.
They are both the same and bad practice. Names should be considered a debugging or prototyping tool and should rarely be relied on.
I believed you, but tested it anyway, and yeah you right ๐ Maybe I had been lied to or I'm mixing it up with something else
it's not "guaranteed" in the sense that it's not officially documented exactly how it works anywhere, so you should probably use Awaitable in 2023+, but you can rely on the implementation to work a certain way in older versions
This message is probably what originally confused me ๐
Yeah I'll use Awaitable once I go 2023
iirc there actually is a very minor difference depending on when you await, because it can return control to you on the same same frame you started from if you await before the point in the loop the sync context updates... but most of the time i use Task.Yield it's in a loop waiting for something, so it's not a huge difference
and you can write a small wrapper checking the frame number if it does matter
Hi friends, I am generating a grid of objects at runtime and deleting them at runtime by clicking on them, and I want to show the number of tiles available on each side and also on the cut like showing in the image all sides (6 - 4 - 4 - 6) and on the cut (2 - 2). so how can I easily do this. thanks!
Seems like a relatively simple algorithm that walks around the perimeter of the shape, counting up until it reaches either empty space or a block in front of it.
Might be easier to do something like going through each row, and then iterating through the spots on the row before and the row after. When you find an empty space, count it and keep going until you don't find another empty space. Take that number and put the number half way between the number of spaces you found.
Then rinse repeat for the columns
Hey guys, im having some trouble dealing with my scene management system.
For some reason my MainMenu scene is not unloading whenever i call the startGame function
as you can see, i've tried some things already
public IEnumerator StartGame()
{
SceneManager.SetActiveScene(bootstrap.LoadedScene);
UnloadScene(mainMenu.BuildIndex);
yield return UnloadScene(mainMenu.BuildIndex);
AsyncOperationExtensions.AsTask(SceneManager.LoadSceneAsync(HUDScene.BuildIndex, LoadSceneMode.Additive));
yield return LoadAsActiveScene(gameplayScene.BuildIndex);
isGameStarted = true;
}
public IEnumerator UnloadScene(int index)
{
AsyncOperation asyncUnload = SceneManager.UnloadSceneAsync(index);
while (!asyncUnload.isDone)
{
yield return null;
}
}
Would appreciate some help, it is not my only loaded scene neighter it is the active scene whenever i unload it
How and where are you calling StartGame()?
Also this will do nothing on its own
UnloadScene(mainMenu.BuildIndex);
ok.. but the coroutine will, wont it?
yes
im calling it from an object in the MainMenu
show the code for that
You need to start coroutines the proper way: StartCoroutine
I've not used AsyncOperation .. doesn't this also need calling?
But yeah what's with AsyncOperationExtensions.AsTask(SceneManager.LoadSceneAsync(HUDScene.BuildIndex, LoadSceneMode.Additive));
private void OnCharacterSelected(CharacterData character)
{
StartCoroutine(SceneHandler.instance.StartGame());
}
its called from an Ui Button
its just me trying to be able to load scene asynchronously so i can add loading screens later on
SceneManager.LoadSceneAsync does that already
anyway have you tried adding logs here?
TO make sure all the code is running as expected?
i mean, the HUD and the gameplay scene load as expected
its just the main menu not unloading for some reason
soo add some logs to the unload scene coroutine?
make sure it's fully executing as expected
I mean presumably the coroutine is finishing if it's getting to those lines
do you perhaps have multiple main menu scenes open?
thats it, i had an unloaded main menu scene i was working on in the hierarchy
thanks!
extend from Osteel solution a little bit, you need to make one look up tables with size = AABB of the shape extend by one row and column for different size eg if the AABB is 4x8 then the look up tables should be 6x10, then perform the scanning
eg if you have a shape and scan row by row
XXXXXXXXX
XAAAXXXAX
XAAAXXAAX
XAAAXXAAX
XAAAXAAAX
XXXAAAAXX
XXXXXXXXX (X means empty and A means there is a tile)
then your look up tables when finding the left perimeter should be
000000000
100000100
200001000
300002000
400010000
000100000
000000000
and your look up tables when finding the right perimeter should be
000000000
000010001
000020002
000030003
000040004
000000010
000000000
basically for the left size, table[r][c]=table[r-1][c]+1 if grid[r][c+1] (right cell) is not empty and grid[r][c] is empty else 0, the look up tables is filled with 0 first, after assigning the perimeter for one side, reuse the look up table
your next task is getting back the perimeter from the look up tables and assign the perimeter back
your problem not that difficult, but many edge cases
(the size of look up table can be smaller btw)
Greetings, I am struggeling with an issue, if anyone has time to look at. Using Vuforia, I want to make so that when both ImageTargets/Objects are within the ARCamera View, they rotate. So when one is not within the scope of the Camera, then the other one that is, does not rotate.
As shown in the images, this should do the job. However, this does not work. What's even more strange, I have tried making logs and finding unusual feedback.
Situation 1: Without changing anything. Cube and Cylinder alternates between true and false, when it should be always true since they are within the scop of ARCamera, so they should always behave like "OnTargetFound".
Situation 2: In the imageTarget's inspector, I checked onTargetLost box, so now when the object is not within ARCamera View, it also returns true. But the log is still returning false somehow.
Situation 3: I changed the code to be:
public class ObjectRotationManager : MonoBehaviour
{
private GameObject cylinderObject;
private GameObject cubeObject;
private bool cylinderInTargetView = true;
private bool cubeInTargetView = true;
void Start() {
cylinderObject = GameObject.Find("Cylinder");
cubeObject = GameObject.Find("Cube");
}
And I am still getting falses.
However, if I put this
cylinderInTargetView = true;
cubeInTargetView = true;
inside void Start(), now it returns true always. However, it always returns true, even when the object is out of ARCamera view.
I am rather disoriented and would appreciate any feedback on this topic.