#archived-code-general
1 messages ยท Page 31 of 1
I am checking if certain methods are not stripped away.
why?
Because the project I'm working on uses a library that doesn't directly call these methods. So if stripping is set to high they are removed.
We try to not use Unity services for anything though, they accidentally disabled our license keys once and it shut down a major project the day a hospital release was needed. That kind of ended us depending on Unity for anything
Yeah I'll likely end up migrating away from jenkins for building stuff, then some kind of VM or docker deployment to actually run the built applications
Oh my god, you build hospital software?
okay. so your saying the y of your xy problem is
Causing exceptions at runtime. I want to set stripping to high since it removes a lot of memory usage.
Yup! Stroke, dementia care and autism ๐
y: "sometimes, some methods are stripped away, and i would like them not to be"
is that correct?
are you familiar with the [Preserve] attribute?
The question I have is. Given a System.Type can I somehow get which line that class is defined?
Hense the complex as heck build server and QA requirements ๐
are you familiar with the [Preserve] attribute?
Yes, the code I'm writing is checking if the preserve attribute is on those methods.
Yeah I've heard of teamcity and the pricing seems pretty high for our needs
At a past company we had a great experience with Jenkins though.
what I have now generates a list of these types but in type names, rather than file/linenumber
you can use link.xml to achieve this too
what you are doing doesn't make sense.
Team city does have a pretty good free tier now though
anyway, no, you cannot get the line number, sorry. it will take you longer to verify this stuff and write the linter than it would be to fix it once
your library sounds buggy
I'll definitely have to try the free tier on some personal stuff. I like the on prem options when I can get them
it should call the methods directly
Oh yes, I very much don't like it. But it's a 5 year old project and I joined it late.
you are developing a video game and you're trying to use a sophisticated feature, code stripping. you should spend the time fixing the library
well
no one is going to use the linter but you
so think this one through critically
They already have unit tests running
The plan is to run it inside a unit test to conform with the current workflow.
it's hard for me to be helpful. you're asking how to directly reference methods by not directly referencing them. you have to fix the library
it is a colossal waste of time to write a linter for this. fix the library
Yeah, I understand and if I had any say in it that library wouldn't be used.
if you can already mechanistically determine which methods you need, you can generate a link.xml instead*
it doesn't make sense to author a linter. just generate the link.xml
yes
why wouldn't you be able to?
anyway, you haven't really gotten to the y of your xy problem
Assets\Scrips\SelectionManager.cs(9,5): error CS0246: The type or namespace name 'Text' could not be found (are you missing a using directive or an assembly reference?)
what are you trying to do?
those shamone now how to fix this
what is going on in the game?
well you're missing a using directive, like it says. #๐ปโcode-beginner
i have it but the place wear i should but it those not show
Text Is the the UI namespace
Is there a way to include the detail meshes into the terrain heightmap? For example, if I paint a bunch of 1x1x1 cubes onto a flat terrain, there should be a bunch of height=0.5f on the heightmap
If there's a way to do this with trees, that would be great as well
My base problem is that I need to decrease the memory usage to avoid crashes at runtime on certain platforms.
Through profiling I've located that 90+ MB can be removed by enabling high stripping (this is a lot more than most other areas).
The problem is that the game is using this dependency injection system that creates various objects and feeds them their arguments into their constructors.
These are stripped away and there are a few 100 instances of this.
I've written code that identifies the types and I can go through and fix all these. But unless I can get some sort of system in place that detects cases. Any new class added to the game would cause a runtime error on that platform.
can it be done in unit testing?
So my goal is to run some reflection code in a unit test which can find all of these cases. and print out the file/line of that class rather than System.Type.FullName
Well a playmode unit test
?
can you be more specific? do you mean il2cpp on ios?
NDA platform.
But yes, it is il2cpp
Is there some optimization that can be done?
Are there memory leaks? How large are your memory leaks?
There are other optimizations that can be done.
NDA: "not doing anything"
But decreasing the executable+dll size is the low hanging fruit I've located
Seems like a lot of work for low hanging fruit
well good luck on your journey here
Thank you.
I'd go through every class and check Update loops first
What donโt you get
i'm not sure what platform would be sensitive for a 5 year old game
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelectionManager : MonoBehaviour
{
public GameObject interaction_Info_UI;
Text interaction_text;
private void Start()
{
interaction_text = interaction_Info_UI.GetComponent<Text>();
}
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
var selectionTransform = hit.transform;
if (selectionTransform.GetComponent<InteractableObject>())
{
interaction_text.text = selectionTransform.GetComponent<InteractableObject>().GetItemName();
interaction_Info_UI.SetActive(true);
}
else
{
interaction_Info_UI.SetActive(false);
}
}
}
}
!code
๐ Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
The game has been in development for 5 years.
yeah...
And the namespace is still missing
what name space wich line
well what would be most helpful?
it sounds like you started working on a game recently that is poorly engineered, and you're being asked to do something that doesn't make sense, it's not clear if it was your idea or not so don't take that personally
you can't tell me what platform it's on, which isn't sensitive, but you think it is
i am no expert, but it stands to reason if you're writing linters to work around DI, which was a fateful and bad choice, this game is going to take 10 years to develop
The overall game isn't poorly engineered but there were some early decisions like relying on dependency inject that are definitely things I wouldn't have done even 5 years ago.
The overall game isn't poorly engineered
you know the 5 stages of grief don't happen in order or one at at ime. you can experience denial and anger at the same time
The game is already out, but not on the platform I'm currently developing against.
okay i mean you can see in this chat, people talk about the switch, quest pro, various HMDs all the time here, it of course doesn't violate any NDAs
i'm not going to know what the game is, and it's not even going to be sensitive that a game is being released for a platform...
anyway, i'm not trying to raz you up on this
90MB is both a lot and not a lot of memory
@polar marten I'm not taking any offence to what you're saying. I think it's quite reasonable.
okay okay
just checking
you can rip out DI in a week. that would be the best solution. the thing probably has 1 implementation of everything anyway
otherwise, i think you should generate link.xml
and avoid requiring [Preserve]
you can also simply preserve your player assembly
And yeah 90MB isn't a lot but when we only go above our memory cap with about 200MB having a simple setting that we can change to get 90MB back is very tempting.
yeah that makes sense to me
it pre made scrip so i dont now anything about it
i think you should try a simple solution first, like preserving all types and members in the player assembly using link.xml or the attribute (i forget which one is for assemblies)
and see what happens
Well you're in #archived-code-general , you should know what a directive /namespace is
you are probably going to get 90MB back from generics in a serialization library, not from your player assembly
The main thing I want to avoid is that other team members that aren't directly working on the port will commit things by mistake that causes crashes, I rather have a nice "Hey, this class is missing [Preserve] on its constructor, please add it."
yeah only link.xml will really protect yo ufrom that in the long term
or freezing usage of DI
not in C+
I'll look into it more as I understood it you had to be very specific for the method.
link.xml is very flexible
c+?
it is the language this scrip is made in
what is the language then beguse its say c+ as the language on the website i found it
where, show me it says c+
C+ is not even a language tho
It says C#
where do you see C+
For some reason my tiles have their colliders 1 pixel bigger than their sprites are, why can that be?
oops
Just a guess, but do you use atlases for your sprites?
yea it say c# i am dume but still dont now how to fix beguse try everting and it still not working
It's a multiple type sprite
again. Ur missing the namespace for Text
do you know how to look it up in the docs?
a c# basics would help you understand what it is
no i just sarted game deving
alright post in #๐ปโcode-beginner
next time
i am on it
Anyway, You should probably learn about TextMeshPro.
It behaves exactly the same as Text component but it's now the standard text and Text is Legacy
i still dont see the problem
@deft pebble could you help me with it?
well then you outta take some basic c# courses before proceeding
this is not a code question
like at all
๐น

Sorry, I don't have much experience with 2d, but my guess would be that the slicing in your sprite file is not precise
@pine jungle #๐ปโcode-beginner
If I had to say, it's very imprecise, but I don't know why...
Here's like a 13x13 selection
nOt A cOdE qUeStIoN
nOt A cOdE qUeStIoN
how to reduce amount of gameobjects in a 2d game? I'm trying to make a game similar to terraria just for fun and I havnt ran into the issue yet but I do know that once im trying to make an actual world (and not just this small testing area for debugging while making it) having every block be its own gameobject will be way too laggy. Is there any way to try to reduce the amount of gameobjects im using for the world while still being able to interact with each tile (just the size of a 1 by 1 square) separately. Also are 2d gameobjects more efficient than 3d ones?
You could use DOTS(TM)
chunk loading probable?
Also, not sure in 2d, but minecraft just generates all blocks as a single mesh, you probably could use this approach in 2d too
would I still treat them all as seperate gameobjects, just disable them if a certain range away from player? Or is it different than that
possibly. If they are all a single mesh how can I interact with each "tile" seperatly or smthn? Do I misunderstand something about mesh?
You would have to have some sort of array that contains data with all the tiles, and when you want to check which tile is where, change this array
But having a huge array of structs still would be much more efficient then having tons of gameobjects
yep
I remember I saw a vid where someone explained how terraria managed to have this insane count of tiles, let me check
It's not Unity related, just a general concept
Ok. If you could send me that if you find it please send it, and thanks
Single mesh? Pretty sure they are chunks
but is each chunk a single mesh?
Yeah, and chunks are connected into single mesh iirc
(idk anything about chucnks or meshes)
Chunks aren't invidual no
ok
if you find it ping me with it plz ๐
seems like learning that stuff might be smart down the line
Catlike coding or Red has good articles
I think sebastian league did one as well but cant recall exactly
I think it's this one @thick socket
https://www.youtube.com/watch?v=YIDbhVPHZbs
I'm a professional programmer who works on games, web and VR/AR applications. With my videos I like to share the wonderful world of programming with everyone!
DISCLAIMER:
This video is not actually representative of how Terraria works. The research I did for this video turned out to be inaccurate and inadequate for the purpose of this video. ...
lol
Nice video title
the title says "Redacted: Mostly inaccurate" ๐ญ
yeah... back when I watched it, it wasn't redacted ๐
xD
4:48 - Chunks? Yeah, Terraria has none of that. At all. It never did. It just uses a giant Tile[,] array, which is idiotic, but works for vanilla version of it.```
In the comment section
The huge "redacted" comment is actually pretty useful
How come this script also grabs the parent's rect? Shouldn't it only get the children's rects?
using UnityEngine;
public class SpaceOutTest : MonoBehaviour
{
[SerializeField] private Vector3 space;
private RectTransform[] rect;
[ContextMenu(nameof(SpaceText))]
private void SpaceText()
{
rect = GetComponentsInChildren<RectTransform>();
for (int i = 0; i < rect.Length; i++)
{
rect[i].localPosition += space * i;
print(rect[i]);
}
}
}
https://docs.unity3d.com/ScriptReference/Component.GetComponentsInChildren.html
The GameObject that you call GetComponentsInChildren on is always searched regardless.
But why?
That doesn't make sense does it?
I only knew those functions were like that. I have no idea why they do it this way of course, seems rather unintuitive.
seems rather unintuitive
Yeah I'd say the same, it's confusing as balls
So how can I make it that it doesn't take the parent then?
Regardless it takes it. So you need to skip it in the foreach
Should I just make it a list and remove the first element?
Seems risky, you could just do if gameobject != rect.gameobject
Why's that risky
It says nothing about sorting, if you want to take that risk that's fine by me. I have no idea if IL2CPP for example would give a different result then mono then or whatever.
the first object isn't for sure the parent + you could accidently have the component removed or use this script on a different object and miss it.
generally it's just bad practice
I mean the only thing it does is you slap it onto a parent and it spaces out the children by a set amount
so it's just a save 1 line to check for the game object
So it's not a real big risk
if gameobject != rect.gameobject = no risk ๐
I suppose but I don't see how it'd fail
But you do you
it can be an annoying bug that you will find in a later debug
Imagine you use this script on a different object that doesn't have the component you are looking for.
you find it in the children and remove it from the first child.
than your script missed it's point
It's still dependant on the index though, currently it causes the first child to be moved by 60 instead of 0 due to it doing space * 1 instead of * 0 since it increases the i due to the parent
What if I just do that if, and remove it from the list if it succeeds?
Yeah, you could do that. You could also have an extra index outside that counts the valid rects, and don't ++ that one if it is the current gameobject.
Many ways to go about this.
Np 
This works now :D
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class SpaceOutTest : MonoBehaviour
{
[SerializeField] private Vector3 space;
private List<RectTransform> rect;
[ContextMenu(nameof(SpaceText))]
private void SpaceText()
{
rect = new(GetComponentsInChildren<RectTransform>().ToList());
if (rect[0] == (RectTransform)transform)
rect.Remove(rect[0]);
for (int i = 0; i < rect.Count; i++)
{
rect[i].localPosition += space * i;
print(rect[i]);
}
}
}
So, I'm trying to have bullet swapping based on my character's typing. The bullet prefabs are different instances. Below is how I organized it in update:
if(boost>=100 && slimeType == 1)
{
projectile = GameObject.Find("FlameBullet");
}
else if(boost>=100 && slimeType == 2)
{
projectile = GameObject.Find("IceBullet");
}
else if(boost>=100 && slimeType == 3)
{
projectile = GameObject.Find("RockBullet");
}
else
{
projectile = GameObject.Find("SlimeBullet");
}
!code
๐ Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
Saw the 3 tick thing after I posted.
Interesting, didn't know you could do (RectTransform)transform, would have expected a getcomponent of some sort.
Do I need to add something after "find" to initialize it in the slot in question?
You still miss the !cs
Cool, that's the fun part of being here ๐
:D
on another topic, i am trying to have my gameObject stand on a tree (this is a squirrel controller if ur wondering). so i am casting a ray from my position to the tree and setting my rotation to the normal of the hit. does anyone see a problem with this approach or even have a better one?
Ray ray = new Ray(transform.position, toTree);
if (Physics.Raycast(ray, out RaycastHit hit, 5, LayerMask.GetMask("TallVegetation")))
{
if (hit.collider.gameObject == targetTree)
{
transform.rotation = Quaternion.Euler(hit.normal);
//body.AddForce(-hit.normal);
}
}```
There/
What slot in question? I don't really understand what you want to do with your code. Do you want to do some kind of prefab stuff?
Yes
So why not just use prefabs?
I want to swap the prefabs into that "slot".
I want to, but I have multiple prefabs that I'm trying to swap in, but I don't remember how to.
So you have 1 slot Projectile, and you want to put different bullets in it?
Yeah. Projectile is the "holder" so to speak to house what type of object is shot.
I would just have an array of all the projectileTypes, and get a projectileType and set it in projectile.
So an array of prefab Bullets, you could also just serialize them independently if you would want. Doesn't really matter much with 4 types.
Alright, thank you, that should help me narrow the search.
hi, I have a prefab with child objects, but if I instantiate this prefab, it only creates the parent gameobject. how can I fix this?
that's not how Instantiate works, so I'd assume your prefab doesn't actually have children
or the children are being destroyed by your code right after being instantiated
oh then how can i duplicate a gameobject with children?
i also tried by setting it as a gameobject instead of a prefab, but same result
Asking again how can I make a Navmeshagent not decelerate instantly when reaching its destination
Instantiate duplicates it with all children
There's no way to duplicate it WITHOUT its children
show your setup and your code
and prove me wrong
then i am confused because the gameobject definitely has children
but I think you've just set something up wrong
show us
show everything
Click here
where does this take you
(make sure project window is open when you click it)
does it take you to somewhere in the project window? Or to the object in the hierarchy
๐ Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
do any of the ther objects have scripts on them?
For example Snake Head?
and lastly can you show the rest of this script?
Ok do you have any scripts in the scene with OnTriggerEnter or OnCollisionEnter
yes
I think it's almost definitely something in this script
DestroySnake is running perhaps
yeah
weird if it is but gonna check now
oh youre right
weird thanks
seems like you have two bugs then:
- DestroySnake is running when it shouldn't
- DestroySnake is not destroying the entire snake, it's leaving that top level object behind
yeah so i have collision detection between snake parts and i guess when im instantiating the ai snake, its own snake head is colliding with its own snake parts
so just gonna make sure that doesnt happen
thx for the help :)
that will happen if they have their own separate Rigidbodies
Hello guys. I have a small problem with my code. Im trying to do a little physics game. The code works and all, but i dont really want to move the center of mass. I though about creating a hinge joint, but that sadly doesnt work. Now can someone help me with my problem?
sorry for posting here but can anyone tell me why is my game build on black screen ?
i made another scene (this one) just to test and still same problem
why are you changing the center of mass in your code
probably exported wrong index in Build Settings
also not a code question
next time use #๐ปโunity-talk
Well i want it to be reallistically rotating, like if you grab something i want it to rotate around the grab point.
when you grab something in real life, you don't change its center of mass
Yeah i know, i did not find a different solution
all you need is a hinge joint correctly anchored at the position you grabbed it from
generally you'd also create an invisible kinematic Rigidbody at the mouse position, and use MovePosition in FixedUpdate to make that invisible object follow the mouse
that will give you realism
attach the hinge joint to the invisible object
you'd also need to use theBox.transform.InverseTransformPosition to get the correct local space position for anchoring the joint
correct scenes index, it's littealy one scene and the one i did open
Ok, im gonna try this out.
show build settings real quick
Theses ?
what does Game View look like in Editor
i removed all the scenes and made a new empty one to see if the problem is only in specific scenes or in all of them
like this
do you have any compile errors when exporting? have you tried another scene too
does only happen in build or in Playmode too
only in build
i got these warnings for the first time, for shaders that are NOT used in this scene
i'll try removing them and building
maybe, they are just warnings and for shaders you may not use but yeah try
i really got shoked this morning when i tried to build for the fist time
UI elements renders but anything else dont
what kinda PC u got ?
are you on a laptop or something
is the game still running in the background?
yes im on a laptop
not the first time i did build a unity game on it
but first time igot the black screen
removing those shaders didnt help still black screen
hm maybe it doesnt support those shaders on ur laptops limited GPU
not the first time i use them...
this scene also has no shaders since its a default skybox + cube
i'll update my graphics
have you tried, new blank scene, different camera , no post processing
start eliminating one possibility after another, debug
@trail mist assuming a blank scene with just a camera in it renders as expected can you try and narrow it down a little more. for example go to ur scene and disable everything then re enable things one at a time until the problem re appears. its a bit brute force as far as trouble shooting go's but you didn't give much info
thats the scene i've been showing you al time
i got this warning after building the empty scene
does it render as expected though?
no. black screen
wait it's not finding Player assembly
hey im having trouble with lerp basic lerp stuff i would assume
whats error say
Vector3 doesn't have a .position
ah yes
which is exactly what the error will say
ok ya try and address the warning. Im not sure specifically how to fix that off the top off my head but that would be my next step if it was me
no Idea what I read those as Transforms xD
Um a missing Player maybe a problem
if they are talking about the Player that runs on your PC to run the game
thank you now the t is the only thing needs fixing says the name t doesn't exist
you can't use variables that you never defined
you never created t, so t does not exist
thank you
what threw me off is you kinda wrote it correct the firs time xD @dusky coral
except for t
would {SerializeField} private flot t;
lol
it's [SerializeField]
you still need the t to move
like t += Time.deltaTime
but this isnt correct way
the link I sent you show example how
ok thank you
building after disabling burst compilation : results
it's not the burst compile
Im litteraly ttrying anything i read online
ill reboot real quick brb
Did you try another project ? is it only this
im trying to import my monobehaviour into my unit test, but i cant figure out how.
using System.Collections;
using NUnit.Framework;
using UnityEngine.TestTools;
public class NewTestScript
{
// A Test behaves as an ordinary method
[Test]
public void NewTestScriptSimplePasses()
{
// Use the Assert class to test conditions
}
}
separate file:
using System;
using UnityEngine;
public class ShipPlayerInput : MonoBehaviour
{ ... }
it doesnt know ShipPlayerInput by default in the test script and i cant figure out what to import
was thiking of trying on another project and will do rn
i have this projects that have similar shaders so ill try
it will take some time so brb
you probably didn't set up the assembly reference from the test assembly to your game assembly
And/or didn't create the test assembly and/or game assembly in the first place
Question regarding ScriptableObjects:
Pictured is a ScriptableObject I have created as it appears in the Unity inspector. It is created from a class called Item that inherits ScriptableObject. I have created this Item from the Create Asset Menu, and put in a few details relevant to this item.
The Item class has an enum called "ItemType", and by selecting "Seed" from the drop down menu in the inspector, this particular Item's itemType is set to "ItemType.Seed".
I want to display different values to be modified in the inspector based on the "itemType" that is selected by the user. For example, "ItemType.Weapon" might have variables that I want to change in the inspector called "attack" or "speed", however, "ItemType.Seed" would have no use for something like this, so I might want variables such as "growthRate", or a bool like "canPlant" to be visible in the Inspector instead.
I might be going about this the wrong way... it might be better to create an entirely new script with a class called "Seed" which inherits "Item". So rather than having one "Item : Scriptable Object", I would have other scripts like "Seed : Item", and "Weapon : Item" which are still items, but have their own functionality.
What do you think?
life update : tried another project, and it's fine even with those shaders that i deleted, animations plays sounds are ok everything is ok
ill return to the main project now
and try again
this might be dump but i literally dont kniw how to get startet with unity
all the tutorials start with some done code (ofc not everything) but while reading/watching that i still have no idea how to start from scratch and all the stuff
are there any tutorials that arent like 5 years old but explain this whole thing
ask for help in #๐ปโcode-beginner first
Do you have basics in coding btw ? like litteraly understanding the int / floats / bools / if() ?
understanting them first will make you better since you will understand what the videos do sometime
!learn
๐งโ๐ซ Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/
yes i have the basics from java (and im trying to get into c# which isnt very different)
there's also some beginner c# courses pinned in #๐ปโcode-beginner
create a prefab. change your scriptable object type to a monobehavior. fill in the fields. then, if you need more stuff, like weapon behavior, add another monobehavior.
don't use scriptable objects to compose behavior. use prefabs
where did you get the idea to use scriptableobjects?
I have a bunch of items in my game. These items have different values, such as what they are worth, their descriptions to display in the inventory, the sprite to display in UI etc.
If I wanted to instantiate one of these items in the scene, then I would create a GameObject, and that would copy over the values of the ScriptableObject relevant to it.
I got the idea watching Brackey's tutorial for an Inventory system.
well
instead
make a prefab
and instantiate the prefab
which is even simpler
and easier
and better
in every conceivable way
that you could possibly fathom to dream or imagine in your mind
and never make scriptable objects again
ever, in all of history, for the rest of your life and afterlife
then you owulnd't have to copy relevant values. it would Just Work
there's no copying
and you can compose scripts
to do all sorts of things
Confusion. Why are ScriptableObjects implemented in the first place then? They seem like a good alternative to JSON or XML
see "Reason #1"
Hello, I don't know if my problem comes from code or Unity, I'm quite new in Unity and i'm having objects where I can't set the value :
public GhostBehavior initialBehavior { get; private set; }```
I have this script member in Unity
#๐ปโcode-beginner start with a tutorial. properties do not appear automatically in the inspector. use a field
I believe you could also use [field: SerializeField] attribute to expose the property
(sorry for the wrong channel) thanks for the answers, I'll do the tutorials I just have a project I have to submit soon and I didn't have the time to make all the tutorials I'd liked ^^"
#archived-lighting not a code question
whoops didn't know that channel existed
is something like this possible with function parameters? I know this specifically isn't possible but i'm trying to do this.
public void LoadScene(string sceneName || int sceneIndex)
{
PlayerPrefs.SetString("sceneToLoad", sceneName || sceneIndex);
SceneManager.LoadScene("Loading");
}
No, you can't make variable types. You can make an overload though, ie. two methods named the same but with different parameter types
oooo i did not know you could do this
thank you!
also is it possible to retrieve the version number via code from the player settings?
A quick Google says it's Application.version
In order to teleport a character controller, you must first disable the CC, then change position, then re-enable. Otherwise the teleport fails. However, disabling character controller doesn't fire OnTriggerExit on triggers the CC is currently inside of
So teleporting a CC out of a Trigger doesn't trigger the exit call
how to deal with this
See if teleporting without disabling notifies the trigger exit. Just call Physics.SyncTransforms() right after you change the position to avoid the CC from rolling back
Oh, nice, wasn't familiar with that call. I am sure that will work, lemme see
Yeah that works, nice! I was never thrilled about the disable/enable thing, didn't know there was a more appropriate way to do it. Thanks 
How can I get the position of a UI element inside a scrollrect relative to the content object?
take the red rectangle for example. At it's default position it should have a relative position of 0, which should go negative as I scroll up
Is there a way to check if a GameObject has at least 2 instances of the same script monobehaviour attached? (Basically when a script needs to remove an effect on the GameObject it is attached on but only if there aren't other instances of the same script)
I could use GetComponents and check the length, but is there a better way?
My instinct is that using whole components to represent individual effects might not be entirely how they are meant to be used, at least that's my understanding 
I don't think you are supposed to be adding/removing components on the fly all that much 
I've modded a handful of mainstream unity games and poured over their code and I have never seen a component be added or removed at runtime
anyone?
Perhaps try #๐ฑโmobile or #๐ฒโui-ux
why even have a code channel then
I didn't say you can't ask the question here
Just seems like nobody here at the moment knows the answer, but those other channels might have someone who does 
so if I have like 100+ items you can drop
I should be making 100+ prefabs depending on the item?
Yeah thanks.. Effectively I have other ways to do this (maybe have a single EffectsHolder script that has an array/list of the individual effects applied to the gameobject)
why?
I read this and I'm trying to wrap my head around a way to use an SO that isn't an immutable data asset 
some may store a players inventory in it for ex
or use it to increment timer
Yes exactly. That's what I do, just have a component that handles all the buffs, handles adding/removing them (and also expiring them over time), and makes them available to the stats component (to observe their effects)
?? are you saying that you can modify SO variables?? 
Like at runtime, for all users of that SO ?? 
I've got a list of like Items and everything...pretty sure this would be rough to do in just code
I've seen a tutorial do it ๐ญ
This isn't at runtime though this is at editor time
I just use SO as like a template for data I will use later
At the very least why not split them into separate SO files
Having it all in one file seems particularly annoying to work with
I mean
In a list like that, can't like duplicate easily and stuff
its 1 SO that just holds all my items
It's just like a library of those items, right? You're not changing those items at runtime?
At runtime means, during the game
I think that is how you are supposed to use SO's
correct
But putting it in one as a list like that seems a bit clunkier than having a folder of separate files for each item
that would be a folder with hundreds of files
Yea
seems easier to just store it in a list
As opposed to a list with hundreds of entries, what's the difference?
Idk I'd rather work with file explorer than unity inspector 
fair
You can sort and stuff 
but its a lot more you need to load at runtime for one
you can write code to sort your lists and fill things in inside SO
like a one-off

I filled in like the Sprite name/helmet name
I'm guessing you're not using version control 
then in code set id to go through and set the super long ID to data about it from elsewhere
yessir
git ๐
right, just did that like once or twice
then got rid of the script code and the SO saved all the data that was set
which is why some people use it to store data
cause it can be set in code and stays when you stop playing
I'm not disputing using SOs, I'm not sure what the hate is for when they are used correctly
I'm concerned about the single-file format you're using 
that was my question lol
It hackles every instinct I have
that github said it hates it xD
funny, making it like this is my instinct
make a list that stores all my data
and go grab it when I need it
That github is garbage take
Conclusion
โ DO NOT USE ScriptableObject Architecture โ
Only use ScriptableObject when you need immutable data asset. If possible, don't use it at all. Editing design data with Unity Inspector is horrible. Use better alternative for this too, such as using Spread Sheet.
This take is awful
Use a spreadsheet ??? 
Either you are using SO or GameObject
yeah, hes got some awesome spreadsheet, haven't bothered figuring it out yet tho
Either way you are editing design data with inspector
if there was a youtube video showing like HOW to use his spreadsheet I would probably instantly start using lol
I certainly would not
Separate files are good, editing with inspector is fine, git ingests GameObject and SO files just fine
uh how do I rotate something

i was ignored in the beginner chat
There's also something like FaceTowards
FaceTowards doesn't really work great for 2D games iirc
ex)
protected void Flip()
{
character.transform.localScale = new Vector3(-1f * character.transform.localScale.x, character.transform.localScale.y, character.transform.localScale.z);
facingRight = !facingRight;
}
im not sure what that means but I shall take that into account
๐
If I have one array of objects and I know they can be cast another type, can I just do (Components[]) for example to cast each element of the array?
i tried all of them in the editor and Z was the only one that moved them
Nah it doesn't work that way. If you are using an array you can do ConvertAll
var newArray = Array.ConvertAll(array, item => (NewType)item);
Casting the array like you suggested will fail because an array's contents type doesn't effect the array's own ... castability? lol
I think, uh i did something wrong. Sorry, im not very good with anchors and have never done anything with them. :
One day I'll just type Destroy(gameObject) instead of Destroy(this) on the first try 
Hi all. I want to iterate on gameobjects and animate (animator.SetTrigger) them in order. This doesn't seem to work, the order is not kept. Any direction on how to do this?
C# has magical covariance rule for array
string[] myStrArray = new string[10];
object[] myObjArray = myStrArray;
This is legal.
You get runtime exception ๐
I see
you cast each element by casting each element, not the array
this is the inverse of what @leaden solstice was illustrating right?
E.g.
object[] myObjArr = new[10];
string[] myStrArr = (string[])myObjArr;```
this is not a valid cast
Yeah that's illegal
I'd go with IEnumerable<string> myStrEnumerable = myObjArr.Cast<string>()
is there a video about how to use your bakingsheet somewhere?
seems really useful but not super easy for me to figure out ๐
you would think it's illegal, but it's actually not apparently
https://dotnetfiddle.net/kLXDfO
That array is originally new string[], it's illegal when the array is originally new object[] like Praetor's example
ah right, misread it lol
I'd love to make a video tutorial when I have time ๐
I'm happy to help you adapting it tho
because that's what I want to do.
โค๏ธ
Ill probably reach out to you sometime if I run into issues ๐
I need to copy components at runtime, which requires going through all the fields of a component and filling in the values from the original. But you can only do that once you have created the new component with AddComponent<>(), but by then it's already too late because that will call Awake() immediately on the new object which will inevitably access fields that you had no chance to initialize because they didn't exist up until that exact moment. Is there no way to add a component at runtime without also invoking Awake()?
Ok i fixed it kinda, but the target joint doesnt work anymore then? And it just behaves weird:
Why aren't you using a Hinge Joint
Im
What do you mean?
Ah know i know what you want me to do
I dont know if it will give me the correct results but i will try
@plucky inlet just a tiny update after all that, I realized the package already has an array that contains the selected objects
I only noticed the next day and I feel dumb
you said you're using target joint
hinge joint seems more appropriate
Yes yes, i have figured it out now. I was just stuck on my previous idea.
Hi everyone! I just ran into a problem trying to use visual studio 2019 (I've tried both the "community" version and the manual installation version). Basically, I can open up the code editor while developing a project. Everything's normal, the thing is, every time I hover any text/code in the code editor, it will just crash, no message or anything, it just hangs and closes. Any ideas what could I do to fix this problem?
-Some important information
-I've not opened my unity project in 3 months, however, it doesn't just happen with this one project, it happens with older ones as well.
-by hovering any text/code, I mean putting my cursor over any of the code you would normally write in the editor, instead of showing some tooltip, it just hangs and closes.
-I've not updated either the unity version I'm using for all my projects nor my visual studio 2019, however upon encountering this error I've tried updating visual studio, same error.
I'm going to try uninstalling visual studio 2019 and let unity reinstall it for me and see if that fixes it.
Otherwise any possible solution you could suggest is appreciated
Tho i still have some issues, the object glitches through the ground when i go into the ground with my mouse. And i also want it to drag behind a little bit, like the target joint.
btw, should i put the hinge joint onto the grabbed object or the mousefollower
also try VS 2022
the grabbed object
if you want to copy a component easily at runtime, assign the component as the only one on a game object, then Instantiate that game object
And with my other problems?
@polar marten thanks for the tip but that won't do unfortunately, I need the component to end up on another, pre-existing gameobject because the component requires that exact rigidbody. Can't change how the rigidbody is accessed either since the component is from an asset and not my own.
i think you can change how the rigidbody is accessed
because the component requires that exact rigidbody
This is not a bulletproof reason for it needing to be on that GameObejct
you better start believing in making changes to assets
i thought about that too, but that usually causes more trouble than its worth as you go down the rabbithole of refactoring the asset , especially if you want to keep updating to newer versions
much smaller rabbit hole than what you're trying to do
i just settled for deactivating the destination gameobject right before the copy and then reactivating it
that also prevents awake from being called and doesn't seem to have any side effects from what i can tell
yup, that seems to have fixed it, thanks for the suggestion
btw the red dot is the mouse follower and the green one is the grab location
hello, could someone explain to me why ~0 == -1 is true? I would think ~0 is equal to -2,147,483,648, since all bits are flipped.
Can you answer my question?
Ah, im sorry didnt see youre on idle
Because ints use a "two's complement" representation
Ah i found it. Its going through the ground, because im using Rigidbody.MovePosition which ignores colliders...
ok so im learning perlin noise
and i accidentally made it do this
its cool but idk why it does that
ill shwo code in a sec
Looks like your standard perlin noise sampling to me...
yes but
why when i move the script holder up the thing doesnt move up it just makes waves? the tiles are transform.parented to the script holder object (empty gameobject)
because you're setting the world position of the tiles right here in your script
the parenting doesn't matter
set local position instead of world position
use .localPosition instead of .position?
o
i didnt know that was a thing thank u tho
now it's sliding around n stuf its being goofy
like moving up is fine the whole thing moves up
when i move it to one side or the other it slides a lot like stays intact but doesnt move with my mouse
im just tryina figure out why it works like that
ok well i fixed it by using local pos when i get the x and y variables, but i stil don't entirely get why it works
How can I stop a coroutine and restart it?
Image 1: Coroutine is assigned to a variable and called on Awake()
Image 2: Coroutine instructions
Image 3: The method I call to reset the coroutine.
It seems that once stopped and restarted, the old coroutine keeps running to some degree. It does not truly "reset".
I don't even see anything in the coroutine that's different. What does "resetting" it even mean for you
The old coroutine will not keep running, no
Are you asking about the soil resetting to the "fertile" state or something?
When the coroutine starts, a function is supposed to be called between 10 and 20 seconds.
This functions as normal.
However, after resetting the coroutine, the function seems to be called between 2 - 3 seconds, or earlier than expected, as if the coroutine that was stopped previously continued to execute its code.
Resetting it, in this case, means resetting the timer before the DegradeSoil() function is called.
If the next time that the DegradeSoil() function was going to be called in 13.6 seconds, the ResetSoilDegradation() method should reset the timer to zero, and assign a new number between 10 - 20 seconds for when the DegradeSoil() function will be called.
Yes based on the code you shared this is how it should work
Maybe share the rest of the code?
Hi, I asked ChatGPT about using Events, but Im sure something is missing, here's a part of my code:
Basicly I just want my code to put a string into my console. It's just for Debug.Log yet
Also, I thought we had a way to put text into discord as code? I looked at the read me but it's not there. Was it removed or it's the wrong channel? XD
CreerEchiquier has no use for the clicking, it's not revelant to my question
void Start()
{
Debug.Log(gameObject);
EventTrigger trigger = gameObject.AddComponent<EventTrigger>();
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerDown;
entry.callback.AddListener((data) => { Debug.Log("Hello"); });
trigger.triggers.Add(entry);
CreerEchiquier();
}
!code
๐ Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
this seems like a really weir dthing to do
why do this in code
instead of just configuring the event trigger in the editor
this code is like comically wrong and bad
Because the objet I want to add a listener arnt in the editor yet
make a prefab
you can literally just implement a pointer handler, or drag something into the event trigger instead
I can't make it as a prefab, it's created via GameObject.CreatePrimitive
anyway - PointerDown will only work if the object in question does not have:
- a Collider (if not UI)
- a Graphic (if UI)
and furthermore you need:
- EventSystem in the scene
- Input Module in the scene
- PhysicsRaycaster (2D?) if not UI
- GrqphicRaycaster if UI
you could use a prefab instead of using CreatePrimitive
you can also just write your own script that implements IPointerDownHandler and add that instead of this weird hoop-jumping with EventTrigger as well
I could... I didn't want to XD, but I guess I should lol...
So it needs a collider? argh... I think that's gonna be hard to click on it XD
I want to click on one of these Quad when I need to
i have never used EventTrigger once from code
its really just a thing meant for persistent listeners, better way to do it in code at runtime if needed
Well, I understood why my OnMouseDown wasn't working tho! It has to be from a script attached to the gameObject. (I made a script making PrimitiveType without being linked to the GameObject). Basicly a non-Monobehavior was acting as a ghost-component of my object. I thought I could still use it that way but it seems I was wrong
Does C# treat "const int" differently from "int" because it knows it's value?
Here's two ints initialized, one as a const:
private const int kNumInstances = 3;
public int NumInstances = 3;
Trying to use the Public int instead of the const int I get a conversion error
well read the error, something is a long and you are using a uint
but no adding const just makes it constant
type is still int
... no, they're the same exact lines. The only difference is the final variable on those lines. kNumInstances is a const int, and NumInstances is just an int.
If I change the Test 2 line to kNumInstances also, the error goes away, even though both kNumInstances and NumInstances are both ints.
My guess is that it actually is smart enough to know the kNumInstances is 3 and only ever 3. So the formula of "uint + 3 * int" will safely always be a uint? Whereas replacing "3" with some unknown int makes it riskier? Though by that logic, any uint + uint could exceed the capacity of a uint, so not sure
yeah would have to look into the resulting il more
if its doing that, it really kinda feels like doing a #define NumInstances 3 in C
although the other int in that formula is also a small constant so everything there is all already known at compile time (I want to make it dynamic :P)
well if dynamic just do the casting yourself as needed, or do not create a situation where you mix int types, and just do it all as long
yeah ... this is dealing with memory address stuff which I'm still wrapping my head around (BatchRendererGroup) so I didn't want to mess with types, but will give casting a shot
This entire sample code blows up a ton by trying to make it dynamic
Fixed it
hi everyone, I am making a plugin for my webgl app:
I am using this function (java script)
GetArgs : function()
{
let source = document.getElementById('player').src;
return source ;
},
but I am getting an error when returning the value... I want the src to be returned as a string... can someone help me know if I have to do something before returning the variable?
how would I add mass to this equation?
-gravity* Time.deltaTime/mass
So, I'm playing around with Jobs, specifically parallel jobs. I'm wondering if it's possible to add new jobs to a parallel job struct before it completes, or if I can only create a vector of them, removing the completed ones as they finish.
Also pretty sure you dont need the second * deltaTime when calling Move you are already factoring it in the vel calc
What do you mean add new jobs ? You cant schedule jobs from within a job afik
Basically, on one frame I set up a ParallelJob struct and start it running. It probably won't finish on this frame, so I let it run, storing the ParallelJob in a static variable, then checking every frame if the jobs have completed and doing with the data what I need. However, it's entirely possible that before the ParallelJob completes, the player has done something which requires more of that same type of data being generated.
So, basically, can I add to the ParallelJob after it's started, or do I just create a new one, and make the static variable a vector of ParallelJobs?
Oh, and by Vector, I meant List. Bleh, too used to working in C++.
Its not advisable to read and write to the same collection especially for a paralel job. There is a way to disable the restrictions but you will have to manage your offsets carefully. I suggest simply scheduling another job with the new data and aggregating on the main thread.
Alright. Figured that'd be the case, but wanted to know.
i did -gravity * Time.deltaTime * mass and it does it pretty well
You need to divide by mass
but multiplying seems to make it go faster
its definetly going slower when i set it to 2.5
you are mixing up acceleration and gravity here I think. If you want to move an object with the same "force/speed" as another and the mass is higher, its going to be accelerated slower then the lighter one. Your gravity is just another force that is affecting the acceleration. In gravity, all masses fall equally if their size is the same, otherwise you would be right with your air resistence.
In theory the TryGetComponent should not run if button is not null, correct? (Due to it being && and not &)
if (button == null && !TryGetComponent(out button))
Or does only doing it like this
if (button == null)
if (!TryGetComponent(out button))
achieve that?
It has to check both, because you ask it to be both.
it checks both conditions . . .
the second one would be what you expected
Doesn't it only do that if it's &
you're doing if button is null and if there is no component . . .
Basically its asking the same thing twice
It's in an OnEnable so it gets run whenever the object is enabled again
i see what you're asking. && will only check the right-hand side if the left-hand side is true . . .
And I assume TryGetComponent is more performance heavy than just checcking if button is null, no?
I also don't want it to reassign it for no reason
& will check both conditions, regardless if the left-hand side is true . . .
Yeah so my statement is correct then, right?
This statement
yup . . .
So in terms of execution this'd be the exact same then, right?
well, no. TryGetComponent will not run if button is null . . .
You mean will run?
Thinking about it, I think I used something like
if(object != null && object.Value == 1)
And that did not give me a null reference if the object was actually null, so its not checking the second statement in the if brackets when the first is already false here?
nope, it will only run (check) the second condition if the first condition is true. the first condition is if button == null . . .
I mean yeah but it does the same for both, no?
No, if your button == null, it will never try to check your component, but if its in the same statement, it will check if its null and if you do not have the component
Which makes me wonder again, why my if statement up there is working ๐
TryGetComponent does not run if the button is not null
if (button == null && !TryGetComponent(out button))
And here TryGetComponent also does not run if the button is not null (Again, due to the difference between & and &&)
if (button == null)
if (!TryGetComponent(out button))
Or is this what I'm saying still wrong
Because if this is right, than this is true as well right?
Or am I missing something big here
TryGetComponent will run, because you want the if statement to check if BOTH are being met. You only run the code if both are correctly returned. I am not sure it is foreseeing the next argument in your if statement. Let me test this real quick ๐
&& exits the statement if the first condition is already false, whilst & does not
&& can do that because if the first condition is false, it does not matter what the value of the second condition is
Ohh, okay. was just going to read the docs because I never thought a lot about that ๐
Thanks for clarifying. But then, your statement all the way up is correct. ๐
This might help
https://www.c-sharpcorner.com/code/71/difference-between-and-in
There was a stackoverflow post that explained it well, as well, but I can't find it anymore
I am so used to handle if with always double char statements ๐
By the latter you mean always doing the operator double? So && instead of & and || instead of |?
Or do you mean something else
Also FYI, there isn't really a reason to use & or | over it's "double" form afaik
doubling it up is just more performant
Yeah exactly. I always use && and | , guess its just the years of coding same patterns making me do that ๐
Well then I am on the safe side I guess ๐
And | or ||?
yes, TryGetComponent does not run if the button is found (not null) . . .
Yeah so what I said is correct, right?
the wording makes it difficult to understand, so i changed it . . .
if the button is found, the 2nd condition will not run . . .
Yeah exactly, which is what I want because I don't want it to re-assign or even run a TryGetComponent if the button already has a value
Because you should be using || if you're using |
(Same logic applies)
They both have to run in this case. If button is null the statement will short-circuit since it's already false, and TryGetComponent will not run in that case. Same in reverse when you do an or check with || and button is null.
If button is null the statement will short-circuit since it's already false
Wouldn't it betruein this case?
Dunno what you mean with & since logical and is not valid here as far as I know
It is, but a conditional AND must also be run if you want to check for true
If you want it to short circuit, change && to ||
What is not valid about it?
Try it, maybe it is
I don't think a logical and is valid
I think in this case it will do a bitwise operation with the results of TryGetComponent and button == null, which makes the question if that is possible on two booleans?
Why don't you just use && 
I do I thought you said doing & is not valid though (as in your IDE would throw an error)
I always use &&
I more mean like validity when it comes to creating an if statement if a button exists like this
This probably works, but it's probably not really useful
I think what you do now is if (0 & 0) which is false if I remember correctly
Or if(1 & 0) I think actually
Of course, what do you expect?
I don't know you're questioning everything and confusing me 
I got confused the moment you started wondering if just using & is valid 
Nonono lmao
Only reason I brought up & is to illustrate the difference of && short-circuiting and & not
I wasn't actually planning on using & or some shit lmao
Ohh
I don't think I'll ever use &
Same ๐ Not even gonna keep that in mind from now on! ๐
it's good for bit stuff . . .
Haha
I suppose, but that's a niche I'll probably never touch
anyone konw why this script only works once, i am getting stuck at 0% the second time i try to load
!code
๐ Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
I mostly use it with assignment (when I don't care about short circuit) such as this
isValid &= some_expression;
isValid &= some_expression;
...
if(isValid) { ... }```
BTW, this checks if you can't get a reference to the button if it's not cached?
What do you mean?
Otherwise I count it & and | as bitwise operators.
Please configure your !ide before asking questions here.
If your IDE is not autocompleting code
or underlining errors, please configure it:
โข Visual Studio (Installed via Unity Hub)
โข Visual Studio (Installed manually)
โข VS Code*
โข JetBrains Rider
โข Other/None
*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.
This is the point of the if-statement, right?
they're asking what your statement is checking. the point of it existing . . .
what?
i have been working like this for the past 3 months
If your IDE configured? I am really confused by the way your syntax looks
Lack of highlighting, too much highlighting
yeah, i didnt mind that
^ @thin aurora
Thatโs what I want
Does intellisense work when you're asking for Unity related functions in your IDE?
you mean the autocomplete stuff, yeah, it just complains about the way i write variable or method names
Stuff like Start()
Then disregard what I said. Your highlighting seems very off, but if your editor can give you errors on wrongly types methods or functions, and can autocomplete, it is probably configured.
He just has a different color for stuff, no?
Which is confusing as all balls but I digress
I was put off by the way it's colored in general, but I notice the info above the classes now.
yeah it does all of that, it just wants me to write an _ before private variable names and some other stuff i dont care about
is the look really that off, its the standard intelliJ look
Strange, I donโt think I get prompts for having to write _
And itโs not a local variable if you mean that
It's JetBrains Rider, not VS
yes, i really hate the VS stuff, no offense for anyone who likes to use it tho
Ah that explains it
- You can change
void Start()toIEnumerator Start()that way you don't need to start a new coroutine. - You appear to unload and load the same scene
gameSceneis this intended? - You don't appear to wait on the async object returned by
SceneManager.UnloadSceneAsync()
Probably the majority uses VS
Rider does it different. You can configure Visual studio to structure the way you make classes and everything in it, though. I ask it to write private readonly type _field; fields for anything passed into the constructor, for example.
Interesting
You can disable individual style rules in the settings somewhere
Pretty sure vanilla VS omits the underscore in this case
Probably
- was for debugging purposes, doesnt actually do anything, gonna try the IEnumerator
Is this object Dont Destroy on Load? Or do you have an instance inside the scenes?
no, its an instance in the scene
I don't notice any other issue apart from maybe checking if loadScene.isDone is true when you start the next load that's stuck. since it would just exit the coroutine.
i can tell you what i am doing, i have a title scene, with some settings and a button to start the game, when i start i go to the loadingScene (where this script lives) then i get to the gameScene, when i bet the game i go back to the title scene, trying to start the game again results me getting stuck at 0% progress in the loading scene
Also are you running in the editor or in a build? I know that historically loading scenes in the editor can look very different than in builds with where it blocks/update progress.
i can attempt exporting it, havent tried that yet
Ok, and this script only exists in the loading scene you load to via your Menu scene?
yes, this script only exists once in an empty object in the Loading Scene, and the loading scene is only getting startet from the title scene
unfortunately exporting also gets me stuck at 0%
interestingly it loads when i dont do it asynchronous
Ok yeah, I might be missing something as well here. But I can't spot any errors. And what you say about your structure make sense (assuming all the other loads are LoadSceneMode.Single as well).
If you haven't done it then I would suggest break pointing it, because that might show if there is something weird going on.
(I also haven't done a lot of scene load recently so I might be forgetting some oddity)
this is how i load the LoadingScene
@sweet inlet Why Unity version are you using?
why lol
It's not an LTS though
Tech releases are supported for a year if I recall correctly?
But it doesn't appear to be the latest in the 2022.1.x tech stream
could be that i forgot to update
https://unity.com/releases/editor/whats-new/2022.1.24 is the latest. There is also the new 2022.2 tech release.
i am going to try opening it with that version
I'm guessing it's the UnloadScene part. You don't need to do that.
yes, i already removed it
that was for debugging purposes, to check if the scene was loaded without me knowing
Well, LTS has longer support. It's not exactly a case of stability
I suppose yea
LTS and any other release is as stable as long as it is supported
Fair
LTS is just guaranteed to be up to date longer
yo, im trying to do layer masking with the matrix but it seems to just, not work
i have Enemy/CameraEdge unchecked, my enemy is tagged as Enemy and my colliders are CameraEdge
is there something im missing?
changing to 1.24f1 hasnt helped unfortunately
my enemy is tagged as Enemy
By tagged you mean it's in the Enemy layer and not that it has the Enemy tag?
is there something wrong with this code? cause when I put blocks like
โฌโฌโฌ
โฌ โฌ
โฌโฌโฌ
and place the middle block I get weird holes
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
it's a problem with the mesh.uvs and mesh.vertices and triangles
Darn, well I made a minimal setup in 2022.1.24f1 and couldn't reproduce your problem.
apparently the triangles array is referencing more vertices than actually exist and the vertices array isn't the same size as the uvs array
I'm having a complete brain fart, if I have a unit vector, how's best to detect which quadrant it sits in by the diagonals?
hmmm, is there some setting i changed that could cause this?
If you use dot product you can easily check if the vector is within 90 degrees of another vector. So if you check against two vectors that are 90 degree from each other you can locate which quadrant it's in.
The thing to remember is that you get the nearest result regardless of which "side" it's on, that's why you need at least 2 tests.
yeah I had thought of a dot setup, just seems like there's a simplet way to do it
x > y works for one diagonal
best choice is dot product or get the angle . . .
anyone
naturally this would work - I guess as a thought experiment I was wondering if there's a simple solution using linear algebra
You might be able to do something like treating the vector as a linear equation and check if the slope is within certain bounds. But dot product is very fast to compute and works regardless of orientation so I would recommend using that.
fair
cheers guys
Are you using 2D and set the collision matrix for 3D or vice versa?
That's the only thing I can think of.
when i change it to this it loads into the gameScene properly, but i loose my progress bar
donโt think so, iโm in2D but i didnโt see 2 separate matrices
If you're using 2D (as in Box Collider 2D) then you should change the matrix in the Physics2D
I would suggest remaking this in a minimal project and see if you can reproduce it there.
3d and 2d use different physics engines, so they have separate collision matrices . . .
makes sense
does unity compile scripts "just-in-time" and does that mean variable name length effects compilation speed
C# isnt interpreted like python so var length shouldnโt have an effect on anything
still keep them short enough to read easily tho ^^
@muted grove it can use either, though there are platform restrictions, but even then it uses intermediate language and not c# directly
so variable name length in say, javascript would effect performance?
I would be surprised if variable lengths actually had and effect. They might be tokenised or something similar.
more characters to read to tokenize right
yeah but its probably negligible or something, if the projects not super massive?
I mean with c# everything could be tokenized before itโs compiled to run natively
i guess i just remove the progress bar and call it a day
And I donโt know how common using jit is anyway
thanks guys
Mesh.vertices is too small. The supplied vertex array has less vertices than are referenced by the triangles array.
UnityEngine.Mesh:set_vertices (UnityEngine.Vector3[])
Chunk:MarchingCubes () (at Assets/Scripts/World/Chunk.cs:136)
Chunk:SetBlockAt (UnityEngine.Vector3,int,bool) (at Assets/Scripts/World/Chunk.cs:229)
BlockBreakingAndPlacing:Update () (at Assets/Scripts/Player/BlockBreakingAndPlacing.cs:46)
Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.
UnityEngine.Mesh:set_uv (UnityEngine.Vector2[])
Chunk:MarchingCubes () (at Assets/Scripts/World/Chunk.cs:138)
Chunk:SetBlockAt (UnityEngine.Vector3,int,bool) (at Assets/Scripts/World/Chunk.cs:229)
BlockBreakingAndPlacing:Update () (at Assets/Scripts/Player/BlockBreakingAndPlacing.cs:46)
why does this happen? the triangle to vertices ratio and vertices to UVs ratio is definitely correct
And anyway - afaik with something like javascript the variables are referenced by memory addresses and even if variable name length affected declaration you would deliberately need to create a scenario where it actually mattered
the effect of this is these holes
what downsides will I face in project if I target .net 4.x instead of 2.0/2.1 standard when targeting mobile platforms (or in general)?
can someone help me with the plugin that I wrote for my webgl app?
ok, i think i found the problem, i just dont konw how to fix it
i am having timer += Time.deltaTime; in my Update() and below that Debug.Log("Timer: " + timer); in unity the timer always shows 0
no idea why, doesnt make any sense whatsoever
it just never goes into the if because timer stays 0 for some reason
Hi everyone. I'm trying to make easy to use player effect system for my game, but ... i've encountered some issue which im unsure how to handle. The problem is that supposedly UnityEvents don't fire when i store my effects in non-monobehaviour type class but when i add monobehaviour to it, UnityEvents appear as plain drag'n drop scripts which disables the choice of which functions to fire on event activation.
And here's the code : using System;
using TimeManagement;
using UnityEngine.Events;
[Serializable]
public class PlayerEffect
{
public PlayerEffect()
{
this.timer=new Timer();
this.isActive=false;
}
public string effectName="";
internal bool isActive;
public Timer timer;
public UnityEvent OnEffectStart;
public UnityEvent OnEffectExit;
}
OH NOOOO, i see why, i put Time.timescale = 0f; at the end of the game, i am so stupid, sorry for wasting everyones time
!cs
how/where are you calling them?
Im calling them with Interface function that connects all collectibles. OnCollect() and inside of it i do EffectsManager.instance.playerEffects[chosenID].OnEffectStart?.Invoke()
I've done input system with UnityEvents and it works well but that's a monobehaviour which i guess is the root of the problem
What i've tried is make a wrapper class for UnityEvent stored inside PlayerEffect which derives from Monobehaviour but then again it reappears as plain drag'n drop script in inspector.
I've heard about other types of events but this one can be serialized and that's a huge improvement. For rest of the types i guess i would have to make a custom logic for adding listeners and custom editor etc.
it shouldn't have to be on a MonoBehaviour to run properly. i'd check if i had time
do a quick test. make a serialized c# class with a unity event. create a MonoBehaviour script with the c# class as a field. make a public method on the MonoBehaviour and insert that method in the unity event. invoke the unity in the MonoBehaviour Start method . . .
Just tested. And turns out when the event is attached to a class with Monobehaviour it works correctly. What do i do now? If u have any ideas i'll be glad.
is there a way to stop unity recompiling every time code changes or when you create a new class and have it only do it on a button press?
If i corectly remember there was something in the options try looking for it
I shall keep digging
You can set it to compile only on command, but that isn't as useful as you might think. For example if you make that new class you can't attach it to the button before compiling it
yeah that's fine, it's just when I'm creating several classes or just tabbing back to the editor to check what something was called or open a file, if I've changed even one line of code, I have to wait the 10 or so seconds for the engine to tell me I'm a good boy
Hi, I'm working with Unity and mySQL db, I made a simple project to test the workflow that get all rows of string and int from table and store a single row with same type.
At the moment, storing data generates the following error log
unity A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details.
anyone knows how to solve it?
You've got to dispose of native arrays if you're using them.
I am getting this error:
EntryPointNotFoundException: GetArgs assembly:<unknown assembly> type:<unknown type> member:(null)
I am using an external function from a java script plugin:
GetArgs : function()
{
var str = "A string passed from JavaScript to C#";
var bufferSize = lengthBytesUTF8(str) + 1; // calculate the size of null-terminated UTF-8 string
var buffer = _malloc(bufferSize); // allocate string buffer on the heap
stringToUTF8(str, buffer, bufferSize); // fill the buffer with the string UTF-8 value
return buffer;
}
and in my code this is what I am doing
[DllImport("__Internal")]
private static extern string GetArgs();
and in my function:
string abs = GetArgs();
can someone tell me why am getting that error , it's been hours
Thanks ill try that :]
not a code question #๐ฒโui-ux
Can I not directly update the variable with the GetInt?
Because it doesn't seem to work
there's nothing inherently wrong with that line, however it's really not enough context to know what you are expecting to happen versus what is actually happening
I expect bad to get the value that has been saved beforehand, and I checked, it does have a value
Well, for another variable, but it has the same code as that ยฏ_(ใ)_/ยฏ
you're assigning the returned value to bad, right?
Yes that's what I'm trying to do
wdym "trying" you are either assigning the value returned by GetInt to bad or not. since you did not show whether you are or not i have to ask
oh
For some reason I thought if you would call it that way it'd assign it, but you actually have to do like bad = PlayPrefs...
Thanks
I assume that's what you mean
yes because the method returns the value. it takes a string for the key name and an int parameter as the default it returns if the key is not found. it's not a ref, in, or out parameter
Yeah that's my bad, I though it was ref or out somehow even though that always has to be explicit
NavMesh.SamplePosition sometimes returns infinity? why is that
do I have to manually call base.Method() when I've overriden from a virtual method on a base class in order to call it or does it get called automatically? And what if I have a variable of type "base" which I assign a value of type "child" and call the method there?
yes you will need to call base.Method() if you want the base method to be called from the overriding method. and the child's method will be called even if the instance of the child is stored as a "base"
hi, is there any apparent reason why this wouldn't be working? Light.intensity -= Time.deltaTime;
can anyone help with my post above please?
might just be happening really slowly? Light.intensity -= Time.deltaTime * 10000;
see if it's doing anything
see that's something you need to mention when you need help with something. see #854851968446365696 for what to include when you ask a question
the intensity value keeps revolving around a certain range, depending on the subtraction value
intensity can also only be between 0 and 8
if I don't override the base class method... the base will be called though? (sounds silly to ask now i think about it, ofcourse it will)
yes
word
Alright so to follow up on this, the lights do not appear to change their intensities, regardless of how much I decrease the value by. Printing the intensity value outputs a 0, but the lights are still very much visible. It's not an issue with referencing the object, as I am able to enable/disable them properly.
seems to be something online about render pipelines - you on URP?
I am
are you able to set the light intensity?
instead of mod it
wait..
that piece of code "Light.intensity -= Time.deltaTime"?
are you running that exact code?
that'd be calling the static method on "Light"
Light is a reference to the light component
no Light is the base class for all lights
it would need to be
Light myLight;
myLight.intensity...
sure but they probably have a variable called Light and are changing the intensity value on that
this.Light results in the same thing
is that even possible..?
yes
the only time your variable name cannot be the same as the class name is when it is inside the class you are using. so inside the Light class you couldn't have a Light member, but outside of that you can
that makes me uncomfortable
ok well then carry on Crux, mb, still no idea why it wouldn't be working
it's so odd, I don't see a reason for it to behave like this
could it have anything to do with the Metal rendering pipeline?
cause I'm on a mac atm
out of my depth with that but possibly? idk how maintained iOS builds of the engine are
that sounds
like a pretty fundamental bug though
I'll test it on a windows machine real quick
could always ask in #archived-lighting
Does it matter to do * 0.5 or / 2?
multiplication is generally considered to be faster than division
So instead of / 2 I should do * 0.5f here?
if you can guarantee that it will be a whole number, then yes
I can
If you multiply by 0.5f it has to cast i to float and then cast the result back to int so it's probably slower
So I should do division then?
to be fair it makes absolutely no visible difference
do whatever is more readable and logical
Also i doesn't have to be a float, I can cast it to int
