Quick question I am getting this error You probably need to add a Rigidbody to the game object "Pinky". Or your script needs to check if the component is attached before using it. UnityEngine.Rigidbody.get_velocity () (at <a019610f26d54349b269239d6f729022>:0) for a lot of items and was wondering if there was a way to ignore a bunch or objects in one area
#archived-code-general
1 messages · Page 167 of 1
The code that is producing this error is this ```private void OnTriggerEnter(Collider other)
{
Debug.Log("Hit");
//hit.transform.gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
If(other.gameObject.GetComponent<MyComponent>)
var triggerObject = other.gameObject.GetComponent<Rigidbody>();
triggerObject.velocity = Vector2.ClampMagnitude(triggerObject.velocity, SlowDownModifier); //slows down things here
}```
wdym handle events ?
public method on child script.
parent has a ref to its child script, and calls child's public method inside its event trigger method
hi, I started to learn about compute shaders recently, and I cant figure out how to send an array from a c# script to a compute shader
basically I want to draw a sdf polygon using a compute shader, but controling the amount of points and its position from the c# script, does someone know how I could do that?
`
private void OnTriggerEnter(Collider other)
{
Debug.Log("Hit");
//hit.transform.gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
If(other.gameObject.GetComponent<MyComponent>)
var triggerObject = other.gameObject.GetComponent<Rigidbody>();
if(triggerObject == null) return; // <==== add this.
triggerObject.velocity = Vector2.ClampMagnitude(triggerObject.velocity, SlowDownModifier); //slows down things here
}
`
Or another approach
`
private void OnTriggerEnter(Collider other)
{
Debug.Log("Hit");
// your pasted code does not have a correct set of braces after this IF statement,
// I think this is a copy paste error ??? and the below line could be removed?
If(other.gameObject.GetComponent<MyComponent>)
if (other.gameObject.TryGetComponent<Rigidbody>(out var rigidbody))
{
rigidbody.velocity = Vector2.ClampMagnitude(rigidbody.velocity, SlowDownModifier);
}
}
`
it keeps it in editor. doesnt keep it in build
Is there a better way to easily display debug text in scene other than Handles.Labels?
for that reason, you shouldnt really be using them to save values or modify them during runtime
they're not meant for that reason
maybe you can ask in #archived-shaders
Json is quite easy, the code is quite literally a couple of lines
is there a way to write the following without using object? I tried having the value be Type but then it doesn't let me convert it to T
public class NetworkPlayerInputValue<Type> : PlayerInputValue
{
public object value;
public override T ReadValue<T>()
{
if(typeof(Type) != typeof(T))
throw new System.Exception($"Type:({typeof(T).FullName}) is not valid for this action");
return (T)value;
}
}
nvm I found a way of pushing object casting back to only at startup
I know you shouldn't ask to ask a question but is anyone savvy with Handles.Labels related stuff? Trying to wrap my head around them and have a few questions about how to use them in the way i want to
you gotta also call some json serialize function with WriteAllText, you shouldnt need to use system.serializable
https://www.newtonsoft.com/json/help/html/SerializeWithJsonSerializerToFile.htm
this is with newtonsoft, its just taking the object and making the json string
which you then write to file
so unity uses just c sharp like no modification right>?
it is c# yes, not some variation. you use the unity api on top of it to actually affect things in unity
I am assigning a gameobject in inspector. When I go to another scene and come back to that scene, that script loses reference to that gameobject. Why? Nothing happens to that gameobject I am referencing. I don't destroy it or instantiate it. It always stays in scene.
this entirely in editor or you mean this is happening in play mode?
put error pause on
Is it cuz I sometimes use await task.delay and scenes might change before that task is carried out?
So it stops everything else from working?
I tried using the cancellation token approach but I didn't understand how to do it.
that could be one reason yes, although its not really possible for me to confirm this without seeing the code
what are you using await for even, ive rarely seen true needs for it in unity so far
Unity Services and For getting events to occur Step by step. Plus I use it to get delay before another task happens since it doesn't register if the next task requires the previous task to be complete.
I have replaced Await with invoking a function with delay in my other project since it is a better approach. Yet to do it in this project since the time constraint is really short and I have a lot of Awaits here 😭
hi guys,
my unity gets stuck for a few seconds
I'm sending email with a picture attatchment from unity
but when i send the email
how can i resolve this problem
this is my code
without proper context it really is just hard to suggest anything. I would avoid async as much as possible if you can in unity
heyy im trying to await sence loading how would i do that? i cant do await UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("TheRift");
fixed it
Ah
Wait I realized that the gameobject with the script is not getting destroyed on load 😭 I dont even have the DontDestroyOnLoad on it and yet it stays. Wtf
Okay I realized that the gameobject was not getting destroyed since it had IAP Listener which was not supposed to get destroyed on load. Now it works.
the documentation for LoadSceneAsync should explain it
ah ok thanks didnt know that was a method
You.. just used it though 🤷
Hey, don't crosspost. Stick to one channel
cool
Is there a way to make colliders "compound" without adding the rigidbody?
No
Ok, thanks.
!code
Posting 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.
so should i waatch some yt or some tutorial for unity itself
so it says i didnt fix the compiled errors is there any problems with this code ``` system.Collections;
using System.Collections.Generic;
using UnityEngine;
public class airdash : MonoBehaviour
{
airdash moveScript;
public float Dashspeed;
public float Dashtime;
// Start is called before the first frame update
void Start()
{
moveScript = GetComponent<ThirdPersonMovement>();
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0))
{
StartCoroutine(Dash());
}
}
IEnumerator Dash()
{
float startTime = Time.time;
while(Time.time < startTime + dashTime)
{
movescript.controller.Move(moveScript.moveDir * dashSpeed * Time.deltaTime)
yield return null;
}
}
}
its used as a mid air dash
(ultrakill ripoff)
Show the error
if you dont see red underlines in your code editor, follow this guide
!ide
💡 IDE Configuration
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.
your mistake is a simple one, you're missing a ;
if your IDE is configured, it'll mark with a red underline
oh ok where?
well i use notepad they dont have any red underlines
Then use visual studio
yea weird thing i dont see any red lines in visual studio i have it open rn but not using it as my IDE
then read the bot link
on IDE configuration
use it as your IDE. I dont wish to help someone who is lazy #archived-code-general message and is using notepad any further
alr ill change into visual studio
after you configure, it should mark where you're missing a ;
and in the future ask in #💻┃code-beginner
alr thanks wytea
Anyone know how to play a sound on collision in unity? been trying to figure out for hours now, ive got a grenade that i want to explode on impact, but i cant figure out how to do sound when it explodes
oh yea here is error
They need to configure their IDE, then they can figure it out
Hello, I've watched GMTK's video about First Unity game and Code Monkey's RE on this video, Code Monkey states that you shouldn't use Tag String but Tag Component (or 2 other way that he briefly mentions in the video), could someone explain me how to reference a gameObject into a prefab please?
o k
bye bye notepad
Should I make a thread? 🧵
Well...Thank you
yes i need a thread
my clothes have a hole in them
so i would like a thread
Oh
to fix them
Here buddy <3 ✨ 🧵✨
nice
50 $ Please.
I don't get it how to reference something into a prefab x( I'm so sorry
no
Oh okay
runs awayy
._.
Learn more about serialized references and select the option that is relevant to you
Also please stop jabbering, there is no off-topic on this server
It was some quick jabbering don't worry we'll stop, and okay I'll try to learn how to use serialized references from an object in the hierarchy to a prefab
Wow, it's actually there, but now my brain is fuming x(
i changed it to visual coding and it still didnt show a red underline?
Visual Studio Code?
yea visual studio code
n o
Maybe on Visual Studio Code you haven't installed the plugin for C#
WELL CURSE WORD FOR POOP I DIDNT
thanks deotexh
You're welcome ^^ x)
If I'm not mistaking the picture is C++/C# with a pink background
Nvm it's not
wait one of them has no references
it says no references
WHAT DO I DO
a a a a a a a a
lets move to #💻┃code-beginner because this is my first game
Sure buddy
Hi, you're better off asking this in #💻┃unity-talk . This channel is aimed at helping beginners with coding concepts related to Unity
Cool, thank you!
Hi, is it possible to keep the search window in the new Unity Search to only 1 instance... everytime I do dependency find I get a new window and I have to chase them down to close them one by one.
OK guys, I'm unsure where exactly to post this as I don't really know how to find the problem or solve it. I have a project using the Unity FPS Starter pack (with the controller). For some reason the player's mouse movement gets "stuck" randomly
as in it sticks and struggles to move
Did you change anything related to code?
No. I think I just fixed it though
the movement threshold in the controller cod was set to 0.01 so I just set it to 0.001
hey guys. if I use Resources.LoadAll in a static dictionary class it works fine, but when using Resources.Load in the same static dictionary, Unity quits silently - what am i missing?
Sounds like a crash. Can you share your code?
This is the previous version and that one works perfectly, but it slows the app down when you have 1k+ scriptable objects around
And these functions describe roughly what i try to achieve
If Unity quits quietly I think it's best if you try figuring out when that happends. Is it truly because of Resources.Load in this case?
Thats difficult to debug. It could also be the case that you cannot "add" to a static dictionary, once it has been instantiated
Could anybody tell me please how I could master Unity starting from scratch. Like I know that I need to watch tutorials but how can I actually master it (In the sense of knowing game design and being able to program without constantly looking up things on Google and Youtube)
I watched a lot of tutorials and started by modifying existing project templates
Interesting, I will try that. Thank you.
besides that a programming course does not hurt 😉
True. But how did you move on then to your own custom projects instead of modifying existing templates? Thanks
Hello. So basically, I am making meshes at runtime to mimic glass shattering, but I have come across an odd problem. in this code snippet:
Vector3 p0 = vertices[0];
Vector3 p1 = vertices[1];
Vector3 p2 = vertices[2];
Vector3 triangleNorm = (Vector3.Cross(p1-p0, p2-p0)).normalized; //Get the normal of the triangle | Some normals seem to have a value of 0,0,0
if(triangleNorm == new Vector3(0,0,0)){
Debug.Log(obj.transform.name);
Debug.Log(p0); //not 0,0,0
Debug.Log(p1); //not 0,0,0
Debug.Log(p2); //not 0,0,0
Debug.Log((Vector3.Cross(p1-p0, p2-p0)) == new Vector3(0,0,0)); //Always true
} //All the y-axis are zero tho since that's what they are supposed to be for me
There are some triangles which have the normal be 0,0,0 after the calculation what, in return, breaks the mesh. It might be that the calculations for getting the normal are wrong, but I think it is correct? I know this is most likely not enough information to help me, but I don't quite know what else to give you except for a couple of the logs so feel free to ask me for anything more (these are p0, p1 and p2 in order without the Y axis since it is always 0): 0.010497 -0.002478973 & 0.011 -0.006 & 0.01098285 -0.002593712
I get the same result with those values. They are probably just too close together for single float precision.
But if you know all the vertices have 0 y position, then you already know the normal.
How? if the object is rotated then I can't make it be up.
The y position should stay 0 always, but because they are in a local orientation
Also no, some of those triangles have quite a big surface to break due to that
So the local normal of the mesh is always up. Then the world normal is the rotation of the object * Vector3.up.
Vector3 localNormal = Vector3.up;
Vector3 worldNormal = transform.rotation * localNormal;
I'll try some thing like that, but i don't need to translate it into world coords so, I think this should be fairly simple if that what you said works
holy jesus of macaroni, it works!
Does anyone know if there is a data structure that allows accessing variables as easy as with static classes with static variables but also makes it dynamically extendable? I've tried just using static dictionaries with objects but accessing them is tedious as I need to cast each value everytime
You should use the generic type <T> instead
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/generics
Depends what you really want to do. Generic can be an option in some scenario.
public abstract class Manager<T> : ManagerBase where T : Manager<T>
{
private static T instance = null;
public static T Instance
{
get
{
return instance;
}
}
...
public class IOManager : Manager<IOManager> {}
...
IOManager.Instance
I'm taking a look at Generic. I want to have a class that provides important variables (like game settings) to all classes while being easy to access (without the need of extensively long code), and expandable by config reader or other classes
I have an issue with 2 tiles of noise not aligning. Could it be this small line in the center that causes the issue?
Is the noise a texture of a sprite and each tile is it's own sprite? The line wont be the reason but the effect of this bug. Maybe take a look at the loops in your noise function, maybe you are feeding the Perlin Noise function wrong locations hence why it's slightly offset
It is for terrain generation not for sprites. I have already looked at the loops and it's all fine, the points where it samples the height value are consitent and aligned, so I don't know where the issue lies, and I feel like the discrepancy in the terrain is too large for this small discrepancy in the noisemap
float[,] GeneratePerlinMatrix()
{
float[,] Noisemap = new float[resolution, resolution];
for (int a = 0; a < resolution; a++)
{
for (int b = 0; b < resolution; b++)
{
float xSample = ((float)a / (resolution - 1) * ChunkSize + xOffset) * NoiseFrequency;
float zSample = ((float)b / (resolution - 1) * ChunkSize + zOffset) * NoiseFrequency;
Noisemap[a, b] = Mathf.PerlinNoise(xSample, zSample);
samplePos[a, b] = new Vector3(xSample, 0, zSample);
}
}
return(Noisemap);
}
void ConvertNmapToTerrain(float[,] noisemap)
{
if (currentTerrain == null)
{
TerrainData terrainData = new TerrainData();
terrainData.heightmapResolution = resolution;
terrainData.size = new Vector3(ChunkSize, HeightAmplifier, ChunkSize);
terrainData.SetHeights(0, 0, noisemap);
//Generate the terrain
GameObject chunk = Terrain.CreateTerrainGameObject(terrainData);
chunk.transform.position = new Vector3(xOffset, 0, zOffset);
currentTerrain = chunk;
}
else
{
currentTerrain.GetComponent<Terrain>().terrainData.SetHeights(0, 0, noisemap);
currentTerrain.transform.position = new Vector3(xOffset, 0, zOffset);
}
}
Is the chunk size equal to the heightmap resolution?
It is not, ChunkSize is 100 and resolution is 129, however making them equal doesn't fix the problem sadly
I had another script calculate the heightmap in the exact same way and it worked, but that script was really bad and broke all the time so I am rewriting, but for some reason, the same approach doesn't work anymore
This is the old code, very messy as I said
float pointX = ((float)a / (resolution - 1) * TileSize + xOffset) * NoiseFrequency;
float pointZ = ((float)b / (resolution - 1) * TileSize + zOffset) * NoiseFrequency;
if (LayerCount == 1) //Exception for a single layer, as below code can only handle >1
{
Tile[a, b] += Mathf.PerlinNoise(pointX * DetailBaseValue, pointZ * DetailBaseValue) * ImpactBaseValue;
}
Should i just learn C# before anything else about unity
No, learn both at the same time
Watch brackeys
ok.
129? Why on earth?
Because the terrain resolution has to be 2^(x) + 1 if that's what you mean
If I have a Vector3 point in local coordinates, that is relative to a transform and is on the same plane as the right and up vector of the transform, then how could I translate the Vector3 point to be a Vector2 point on that plane? I have looked into planes in the api, but only found how to put the Vector3 point on the plane (as a Vector3 still), not how to translate it to a Vector2. Maybe something like Transform.InverseTransformPoint is what I am looking for, but I am a little confused about what exactly it does and if it does the right thing.
I wouldn't recommend brackeys only bc most of their tutorials are random one-offs; they don't follow an inherent pattern of learning concepts
I'd watch/read a beginner c# or fundamentals course and check the pinned tabs from #💻┃code-beginner
InverseTransformPoint transforms a local space coordinate to world space. it has nothing to do with getting a Vector2 from a Vector3. it sounds like you just care about the X and Y coordinates of the Vector3, yeah? so just drop the z coordinate and bam you have a Vector2 representing the position along the plane
Not quite so simple unfortunately, the transform may have any rotation and I know that the Vector3 is a local position relative to the transform and that it is on the plane of the right vector and the up vector
I want to treat the right vector as the x and the up vector as the y
And get local coordinates of that point, but in 2d
Also inverseTransformPoint I believe converts world coords to local coords
ah yeah, i had that backwards. still not exactly what you've described though
Doesn't local coords mean that the x is the right vector of the transform?
local coordinates are relative to the object's position and rotation. i'm also not entirely getting what you are trying to do here. you explain it as if the plane is relative to the transform's up and right axes, which would make local coordinates with the Z axis dropped coordinates on that plane, but then you say it isn't?
Does that mean that if I have vertex in a mesh then the x is always the rightvector of the transform the mesh is on?
the X axis is the horizontal axis, if that is what you mean
Yes, I know it is the horizontal axis, but in a mesh, is the x axis for the vertices towards the transforms right vector?
wtf do you mean by "towards the transforms right vector"
or is the x axis relative to smth else
the X axis is the horizontal axis that runs left to right
oh fuck I mixed up the names of these things in different engines, I mean transform.right by "towards the transforms right vector"
so I guess yes it is that
yes, transform.right is the vector that points along the right direction relative to the transform's rotation
Okay thanks!
what is the difference between a class that is derived by monobehavior vs a non monobehavior class? Also, if I needed to get a variable from a non monobehavior class to a monobehavior class, how can I do that
Where does this other variable exist? You get it from whatever API produces it. If no API exists then presumably you new the class and read that instance
There are many differences between Unity Objects and not, but it's kinda irrelevant without context
Hi, I'm having an issue with my gun in a 3d fps shooter game im making. Basically when is shoot the target it registers as a hit and gets confirmed with a debug.log statement but after a certain distance (2 or 3 meters away) the shots stop getting registered and the target doesnt take damage. I've tried plying around with the max distance value and some others but i can't seem to find the solution. Any help would be appreciated.
i can send the relevant scripts to whoever wants to help
I have three scripts,
1.One for equipping a spell. https://gdl.space/utiyudacob.cs
2.One for the stats of that spell, which is a public class. https://gdl.space/aduwijifiq.cs
3.One script that I need one of the stats of that spell (timeToDie) from 2, but getting it from the equipped spell (1). https://gdl.space/oyafewobam.cpp
I don't know how to get the variables from the public class
getComponent<2> doesn't seem to work on 3
in void shootSpell, last line
GetComponent<SpellSlots>().spells
Oh wait I'm a dumbass I forgot what I even wanted to get to in the beginning. So, since the vertices positions are not relative to the transforms rotation, but rather are in their own "coordinate space", then how can I translate the vertices to be a Vector2 with the x being how far on the transform.right the point is and y being how far on the transform.up the point is?
Object space is the same as local space. transform.right is normalized though so it's ignoring scale
But when I do Debug.Log() on the vertices positions they are not relative to the transform.right direction
anyone able to help with this?
spells is an array
I need to find the stats of the equipped spell
What do you mean? The vertices are stored in object space and transformed by the transform, just like Vector3.right is transformed to transform.right
I get this error and I don't know what to do to fix it
It's nonsensical, 1. you don't have a SpellStats component on an object, because 2. it's not a component!
Your equipped spell is a gameobject, it has no connection to the spell stats instance
afaik it's literally just being referenced by spell stats and SpellSlots.equippedSpell and nothing else
so how could I declare the stats in a way so that I can access them?
If the vertices positions were relative to the transforms rotation, then doing vertex += Vector3.up should get me the same position as doing vertex += transform.up right?
as a component on that gameobject, or as a reference on a component, or in a way that you can index back into your spells array to find out which one you're talking about
I don't know what that means exactly, but no?
transform.up is in world space
it's nonsensical to add that to something that is in local space and expect anything meaningful to occur
In my game what you do is you make like a phone, laptop, etc and you get money by people buying your product. but I don’t know how to make it so it is based on how expensive it is and what the specs are. Here is a example for what I want it to be like just it is based on specs and price https://youtu.be/ViUf0e7DMKM 3:24-4:04 top right where it says finale and units. If you could point me to a tutorial or docs or what I should do to achieve that system. Thank you
I hope you guys find this Game Dev Tycoon full game walkthrough playthrough gameplay no commentary video useful.Leave a like and share with your friends if you can ;) .Soon I'll be uploading some new videos about more games.
★Links★
Secondary channel: https://www.youtube.com/channel/UCVM9bpt-sIwXP2xJ9n7v3UA
https://steamcommunity.com/id/fullthr...
God dammit I don't know very well how to describe the problem, but maybe this is better: How would I get how far on the transform.right axis a point is?
Guys, I want to implement a transport mechanic to my character at a fixed distance but the angle according to the position of my mouse, I'm having trouble taking this angle and defining a Vector3
this is my current code, for now it is teleporting to a distance always ahead in x, how can I modify to take the angle of the mouse?
transform.InverseTransformPoint(point) then get the x axis value of the resulting vector
If the point is a vertex, then it's in local space, and you would just need to check its x coordinate
But that doesn't take into account that transform.right has a world space magnitude of 1, so if your object is scaled it will be incorrect.
You can however just multiply the point by the transform's lossyScale and the x coordinate would then be the right magnitude
got it
Hey! I'm optimizing my game now. When I change display resolution on Android device in script with Screen.SetResolution GPU processing time reducing. Does it mean that I have issues with fill rate?
What is mesh.bounds.center relative to? the transforms position?
Everything in mesh is in object space, which is the same as local space
I don't really know how to help you understand the diffierent spaces, I am making a vector guide but it's got a lot of work to do before it can really cater for most things.
That tells you that you are bottlenecked by the GPU. Which means that even if you optimized scripts, physics, or anything on the CPU, you wouldn't see any performance improvements (unless you're also running into power or thermal limits)
While your fillrate might be the biggest culprit, everything the GPU is doing is contributing to the bottleneck. Any optimization on the GPU will improve your frame rate.
I’m new to optimizing so my questions might be too obvious for someone. Is it 100% fiilrate issue if FPS increases when I change display resolution? That’s what the course on Unity Learning says. It’s just that I don’t use difficult shaders. Almost all materials use URP Lit shader
Like I said, everything the GPU does contributes to the bottleneck. Reducing the display resolution will always improve GPU time, but how much depends on how much time your fillrate is taking.
URP/Lit is a complicated PBR shader. For mobile, you should use URP/Simple Lit
Thanks, didn’t know that. I’ll try all the good practices for graphic optimization then
is there a method that is called just with [ExecuteAlways] attribute?
xy problem
is there a method that is called just if [ExecuteAlways] attribute reffers to the whole class?
explain what you are trying to achieve
I probably want someone to answer my question
so far you are asking a weird question which indicates you are attempting to solve something the wrong way
so probably I want to know if there is a method like Start, but that is called when Edit mode is entered, not Game mode
you can hook into EditorApplication.playModeStateChanged
you can use Application.isPlaying
in start, awake
you can extract your own bool from playModeStateChanged
and use it globally
well, start and awake are just called when play mode is entered, so Application.isPlaying doesn't make sense here
wrong
putting it in Update makes sense
well, it is called after game is finished
so yes
it works as OnApplicationQuit with ExecuteAlwaysAttribute
it is called when domain is reloaded
awake is called on everything
all prefabs all components
if you have a prefab with execute always and domain is reloaded awake will be called on it
if you have domain reload disabled it wont be called when you exit playmode
it is not called when I change a script and enter unity
OnEnable is called though
and thank you for your help 🙂
However, because we do not know what you re trying to achieve, we cannot suggest you the best approach
I am just testing things in my script + it's always great to discover smth new
What are you testing ?
Because, you know, testing is made with a goal.
I am trying to instantiate any enum type to set to TMP_Dropdown in OnValidate
Start and Awake called when - loading unity, dropping prefab into the scene in editor, loading that scene in editor, opening that prefab for editing, creating prefab variant, opening prefab variant,
You might want to use a custom inspector ?
is it possible to set an enum there?
thank you
for what?
Yes, it is.
thank you so much, @steady moat thank you too
it seems im not worthy to be answered
at least Simferoce is
what?
He has been asking you to explain what you were attempting to do.
And you just straight up said no and continue to ask question.
well, they have already solved my problem
I mean, context doesn't matter so much here
I am just testing things
serializing Type is already another problem
that is a simple one
attach attribute with id to types you want serialized
resolve using that id
no, I want to serialize a Type
yes i understand what you said
I see, I haven't understand what you have said though. Maybe you could explain it, please?
is there a documentation for this?
I haven't said that I need a library
same principle attach attribute, use that attribute to resolve the type
if you cant attach directly because the type is in another assembly you add it to a LUT
the problem is that enum isn't an object
private Type optionsEnum;
//
optionsEnum = typeof(LevelDiff); // public enum LevelDiff { ... };
this is how I do it with a specific enum
but I want to be able to do it in the inspector
so that I can chose whatever enum I want
that exists somewhere in the script
it will be actually perfect if I could do it by chosing public type from script from dragged object
(as it's done in Events)
I will have to do a research on that actually
yep same thing i said earlier
attach attribute with id
resolve using that id
you can technically use anything as id, like the type name
but id is reliable, name isnt
[SerializedTypeId("someguid")
class Foo
{
}
[System.Serializable]
public class SerializedType
{
public Type type
{
get
{
if(_type == null)
_type = SerializedTypeResolver.GetType(_guid);
return _type;
}
}
Type _type;
[SerializeField] string _guid;
}
static class SerializedTypeResolver
{
Dictionary<string, Type> types;
static SerializedTypeResolver()
{
// collect all types with SerializedTypeId
}
public static Type GetType(string id) => types[id];
}
class SerializedTypePropertyDrawer : PropertyDrawer
{
// draw dropdown selector for all types with id attached
}
in simple terms
I see, that's great, but isn't it then better just to find all enums?
it's even easier than finding specific attribute then
yeah and how will you serialize it
does anyone know any good tutorials on delegates? I'm trying to use them by looking through this article but I don't understand it - trying to apply it to my own code and it isn't working
article: https://gamedevbeginner.com/events-and-delegates-in-unity/
Shows a simple C# delegate declaration and how the compiler converts delegates to normal class type.
thumbnail pretty pog, ill have a look now
[SerializeField] private string optionsEnumName;
private Type[] allEnums;
private Type optionEnum;
//
// find all enums somewhere
//
private void OnValidate()
{
optionsEnum = allEnums.First(w => w.FullName == optionsEnumName);
}
I will have to test it
also thank you for your help 😄
yep as i said you can do it, but its not reliable
I see what you mean
you renamed the enum, you move it, nest it, and all your serialized strings are broken
yes, but the same can be with id
if you rename an enum, you probably will rename the id too
you never rename the id
why?
because its literally a guid string
I think I shouldn't be "id123" for LevelDiff enum
I doubt you'll ever look at a GUID x7x2h27js[...] and think you need to rename it
how do you get this id?
generate it any way you want
i have vs extension that inserts a new guid with ctrl+k+space
I see
you can use interactive window and Guid.New()
Ok So
I am trying to have a looping level of some sorts
where after interacting with something you are warped back to the start and the level is replace, re-triggering the checks for all the various spawnables
however I think because the interactable is a child of the level, its applying the changes to the prefab?
I think?
I can also just try and have the interactable separate and just never move, that might work
its the same difference between unity asset databse and unreal one
i can only speak for ue4, but in it moving an asset would leave behind a "redirector" file
because assets dont have a guid attached to them
resolved by path
unity has .meta with guid
same as this attribute, meaning you can move assets anywhere
doesnt matter
even between projects
references will be preserved
You'll probably have to specify more, when you say level, is this some actual GO you have or are you referring to the scene? Sounds like you are instantiating something but never grabbing the reference
If you generate several layers of perlin noise with increasing frequency and decreasing impact and add the resulting height values together for every position, what is a good way to insure the values stay between 0 and 1 without flattening it to much (for example I tried dividing the heighrt values by the ammount of layers and using a sigmoid function but all made the terrain very flat and basicly destroyed the detail)
I'd say this is a code general question; Say I have a texture2D and a rect, how can I crop the texture2D, say the start is Vector2(120, 512) and the width is 1280 and height 1280. I'd need only those pixels. I've tried googling it, but I just don't get it.
probably something like min/max for every sample
i advice to grab LibNoise and use it instead, or at least to get a reference for blending nodes
getpixels only accepts a mipmap level as a parameter though?
scroll down
ah, i see, thank you
rb.AddForce(transform.up * jumpforce);
hey could someone help me with this error
you've already been told how to solve it
No, you don't
idk what they mean
Don't post in multiple channels, go learn C#
I don't know the maximum or minimum that is the issue and because this thing should generate (almost) infinitly in every direction, I can't wait until all values have been generated to find out what they are
i mean you sample all layers and select max
look into libnoise it should be a solved problem already
there are beginner c# courses pinned in #💻┃code-beginner
start with those and learn wtf you are doing so that basic info like "make jumpforce a float" actually makes sense to you
Ight thanks
look through modules
libnoise is basically nodes, chain them, sample the chain
its much more convenient to work with than with raw functions, you can use or write a node editor and observe the changes in real time
which means you accelerate iterations
so even if you wont use it as is, use it as a playground to create desired results
Libnoise Designer : A visual interface to interact with the LibNoise library.
this is really messing with me, why is your array of Types called allEnums
because this array contains all enums
it contains a bunch of Types
also that was a small prototype snippet
are the Types all Types of various Enums?
yes, but after you assign them, it will contain enums
yes
every enum has its own type, so yes
I see...
why are you inflicting such a thing on yourself @_@;
what do you mean?
usually holding a Type in a variable like this is a code smell unless you are doing something very fancy like making your own custom dependency injection engine
there is no way to do it in another way with enums
and holding an array of Types is really far down that path
do what?
what are you trying to accomplish though
I have written it above
I am making a DropdownEnum script for my game
so that options of dropdown that script is attached to are the same as specific enum's items
this is the only way to do it, so
...huh?
when you say "for my game" do you mean in game, or a custom inspector in the editor?
it's a script with ExecuteAlwaysAttribute
so dropdown's options will be changed in OnValidate
I am just too lazy to write all options manually
this still hasnt gotten to the "but why" part
also it doesn't seem to be correct
like super high level concept: Whats the end goal?
but why?
its not
what problem are you trying to solve with all of this
well, I have said it already...
you can create a custom inspector
no I scrolled really really far up, I seriously do not understand your end goal
like what do you need this dropdown for
lets say the dropdown is working.... then what
e.g. I want to have a dropdown that contains all items of LevelDiff enum
whats the FINAL goal, whats the actual thing you are trying to achieve in the end
be specific
an inspector dropdown?
I will probably to lot's of enums, so I want to change their options by just writing public enum's name
why
what do you mean?
like keep going down the train track
TMP_Dropdown
whats the goal
well.. to not waste my time by writing options for dropdowns manually?
Okay so, in game dropdown then?
yes
Settings menu maybe? Like quality presets, display settings (fullscreen, borderless)?
and you want to "bind" that dropdown to a specific enum, so its an enum value selector?
to all dropdowns that will be connected to public enums in my game
I have said it so...
No, you're too generic
We're missing the context
but like, the core here is you have in game dropdowns you want to have options for, and you wanna be able to map "this in game dropdown maps to that enum's option list" right
yes
Like you have the FooEnum and you wanna bind "this in game dropdown has all the options for the FooEnum" yeah?
exactly
aight, is it runtime mutable? Like do you need to dynamically change "This specific dropdown now is actually the BarEnum values"?
Or will it be set at edit time (what enum a specific dropdown maps to), and then never change?
edit time
basically: Do you need your options for a specific dropdown to be able to change dynamically in the middle of the game
it will be changed at edit time
Aight, I wouldnt use enums at all for this then
no
I will probably use most enums in settings
Enums arent the right use case here, what you have done is you have tried to re-create the Localization stuff unity has
Yes, but I don't use those enums just for that
Cuz for actual strings displayed to the user, IE dropdowns, you should start with normal strings (not enums), and then later you can change from a normal string to a localized string
well, I have this
public enum LevelDiff
{
VeryEasy,
Easy,
Normal,
Hard,
Extreme,
Insane
}
public static string GetString(this LevelDiff diff) => diff switch
{
LevelDiff.VeryEasy => "Very Easy",
LevelDiff.Easy => "Easy",
LevelDiff.Normal => "Normal",
LevelDiff.Hard => "Hard",
LevelDiff.Extreme => "Extreme",
LevelDiff.Insane => "Insane",
_ => string.Empty
};
yeah you have effectively re-invented the localization system
why..
isn't it how it's usually done?
nah
how would you do this?
now we may still be able to enums and then your solution isnt terrible but
I have to sanity check if the localization system works for const accessible stuff in attributes
What about making another class that sets the values?
what do you mean by localization?
I'll bring up some code
you reffer to me?
yes
well, this sentence isn't so clear to me without any code or further explanations
I'll get some code in here
Localization: displaying different things depending on the user's locale settings (language, formats). Translation, simply said, but evolved to other stuff than strings
or you can just explain?
I see.
haven't ever worked with this stuff
but it may have troubles with enums I guess?
public class EnumDropdown<T> : MonoBehaviour where T : Enum {
TMP_Dropdown _dropdown;
void Awake() {
_drodown = GetComponent<TMP_Dropdown>();
_dropdown.options = Enum.GetValues<T>().Select(value => new TMP_Dropdown.OptionData(value.ToString()));
}
}
Localization effectively is the process of mapping KeyValuePairs of "Value" to "SomeString"
Then create children of this class that specify the enum type
oh, anyway it isn't an issue with enums
Im trying to look up how you can GetDisplayName of enums in Unity
you can translate everything in GetString, so no problem
oh, does it even work?
Well you have to create child classes
MVC has an [Display(...) attribute you can put on enums to specify their human readable name
because unity doesnt support generic monobehaviours out of the box
I know @hard viper found a lib for serializing Type, which is fine here if it can be narrowed down to specifically enums
do I have to create all enums that I want to use with this type, or?
I can show
please 😄
theyd have to make a class for every individual enum which sounds like a pain
I was just in a lol game
I do think a Type selector is prolly the right call here
but I think the "convert enum to string" logic can be simplified via an Attribute
unity already has a way to "nicefy" enum names sort of
well, I don't think I should care about localization for my small poor game now
anyway I have almost done it already
This class should work
public class EnumDropdown<T> : MonoBehaviour where T : Enum {
TMP_Dropdown _dropdown;
void Awake() {
// Get the dropdown
_dropdown = GetComponent<TMP_Dropdown>();
// Get the values of the enum and construct a new OptionData from each
_dropdown.options = Enum.GetValues(typeof(T)).Cast<T>()
.Select(value => new TMP_Dropdown.OptionData(value.ToString())).ToList();
}
// _dropdown.value returns the currently selected index
public T Value => (T)Enum.Parse(typeof(T), _dropdown.options[_dropdown.value].text);
}
And then create children with the specific enum type
public class LevelDiffDropdown : EnumDropdown<LevelDiff> { }
I just have to find a way to get not enums from the full Assembly, but from #Scripts folder
If you want this but without the creating a child class for every enum pass, i have something too
GenericUnityObjects?
wdym, generic classes? @gray mural
I will have to create a class for all dropdowns
Are you trying to get every enum type in a specific folder of your project "automatically", rather than manually specifying which enums you want to turn into a dropdown? (just trying to understand your goals)
Yeah, but it's literally 1 line of code
alternatively you can get the GenericUnityObjects package
yes, anyway.
I will have to get all enums in order to find them by name
You make a component that works for all enums. The UI controller class will pass the enum type to the component and then the component can read the enum values from that
amonst Type[] allEnums
It's a lot less boilerplate
but you dont get type safety
i guess its a tradeoff
Yeah
but can I reffer to it like this.Easy (LevelDiff.Easy) ?
Hey if I'm working with unity i have to accept that sometimes i have to deal with tradeoffs like that
Yeah, this doesnt change anything about the enum
It's a completely separate class
Also i dont remember where E : Enum being a thing, am i misremembering
It constrains the type to be a child of Enum
right but the whole point of code is automation so, if theres a way to not have to write extra lines of code, its usually preferable :p
and thus only accepts enum values
I always thought you couldn't do it, huh
its a new constraint that got added a bit ago
that's where GenericUnityObjects comes in
?
Oh wait that's kinda huge
does it even work with constraints on the generics?! 😮
yeah
what Bobbo just linked
life. altering.
I wouldn't call it life alterning
God i wish i found this earlier lol
its more of a QoL
I would lol
It'd have saved a bunch of time for me
what is it for ?
exactly your use case
when you need to be able to specify a type constraint of a monobehavior
(unrelated to apples question) This is how it looks btw, it only shows the valid types in this nice dropdown
oh wait, okay so it still just creates the non generic class wrappers, it just automates creating them
yes
Well... thats still pretty good I guess
it should be way better in terms of performance at least
what would even be better?
Funky code generation
if unity just supported it proper bwahaha
but this does seem like as close as you can get and its pretty close
yeah ig
but without some insane reflection shenanigans i dont see it happening without code gen
My only wish is for interfaces to be assignable in editor
Yeah it doesn't seem possible lol
what do you mean?
oh like, that you drag and drop an interface ref
Yes
yeah itd be nice if there was an IMonoBehavior
Technically IComponent
when would you ever want that though
I only remember that i needed it a few times, forgot the details
MonoBehaviour has like 20 public members
yeah thats true
you would need to reimplement it every time
default interface implementations
Wait that's c#?
I like to just keep pretending they dont
but why not an abstract class at that point
exactly, I seriously dont get the point of them
if you want multiple inheritance
its like trying to progress towards C++ multip- YES exactly
multiple inheritance
which is not considered a great thing to have
well sometimes its useful
I dont remotely understand the appeal of default interface imps, it seems to violate everything C# stands for @_@;
Is default interface implementation even available in unity c#
yes
I'm still on 2019.4 so i might not have it anyway though
ah yeah probably not, it's a c# 8 feature
both my old and new job just straight up forbid using those til anyone could come up with an actual use case for the things, no one ever did
public interface IResource {
string Name { get; }
Namespace Namespace { get; }
string Location { get; }
object Data { get; }
}
public interface IResource<out T> : IResource {
new T Data { get; }
object IResource.Data => Data!;
}
```This is the only use case I've met so far
(not unity)
I'd REALLY like to use it for my use case
IEnumerator also has this stuff
the ability to add methods to an interface without breaking old code
thats not a good thing imo
old classes that implement it
Wait can't you just make an extension class and extend the interface
yeah that sounds like a bad idea
Why is this needed
I use it in my save system to just specify the file name as => GetType().Name.
Each save file is by default saved under the class name and I dont need to specify the key in every single class
me and over like 70 seasoned veteran devs at my last job never came up with an answer to this over a whole year
Huh
Implementing another interface?
Like I showed in my example?
why would you want to do this
can is show enum types?
yes
nice
To have a non-generic and generic version of the same interface
default imp is orthogonal to that
orthogonal?
yes. You can achieve that result still without the weird default imp
you just re-invented the abstract class
You can't inherit from multiple classes though
interfaces shouldn't be a substitute for inheritance either though
public interface IResource
{
string Name { get; }
Namespace Namespace { get; }
string Location { get; }
object Data { get; }
}
public interface IResource<out T> : IResource
{
new T Data { get; }
}
public abstract class Resource<out T> : IResource<out T>
{
object IResource.Data => Data!;
...
}
yeah thats a good thing
I agree
any greybeard C++ dev can prolly write an entire essay on why C#'s single inheritance system is something to celebrate, not try to circumvent
but its implementations that are the problem, not the outfacing interface
whats the issue?
What is => Data!;, what does the ! at the end specify?
It's to suppress the null warning
Null safety stuff
Oh
Crazy inheritance trees where its extremely hard to change something
its just a shorthand for declaring a get property, its the same as writing
object IResource.Data
{
get => Data!;
}
which is a further shorthand for
object IResource.Data
{
get {
return Data!;
}
}
Classes needing to inherit stuff that they don't need/want
like what?
decorator pattern, strategy pattern, composition over inheritance...
"composition over inheritance" yeah that's what im trying to say here
default interface imps are not composition
its weird pseudo inheritance and worse yet, multiple inheritance
its as far away from composition land as you can get
Yeah, you should switch out abstract classes for interfaces
but that's not what my use case is about
well no, its not a principle of "switching out"
object IResource.Data => Data!;
composition is about "owns a", not of "is a"
do you want me to use that package with code you have suggested?
Static Extension Methods, and stuff like Decorator/Strategy pattern, are examples of Composition
I mean i feel like the default interface implementation is just syntatic sugar for doing the same thing with static extension
Interfaces also play a critical part because they enable polymorphism
except it modifies the class but the class downstream isnt aware of this
extension methods "glass box" the logic
Can you elaborate more on this?
I don't see how object IResource.Data => Data! hides anything from the children
if you add a default implementation method, the class implementing the interface now is altared
Weird question, is there a way to prevent a component being added to a prefab/scene in the Editor?
but I do get your point about default implementations circumventing the single inheritance
[HideInInspector]?
prevent it in what way?
Unless im misunderstanding
I think I misexplained it. I want this to not be possible. I think I can do this by deliberately naming the .cs file something else.
In my currently understanding, the class implementing the interface is just as unaware of the static extension methods as the default implementation
yeah but an extension method can only access and manipulate from an "outside" perspective
If anything it's more hidden with static extension since the logic is somewhere else entirely
effectively speaking, adding a default implementation to an interface can potentially break unit tests you have for the implementing class, as its behavior is now altered
yes
There's no private / public when it comes to an interface iterface though, so what does outside perspective mean?
static extension methods, on the other hand, wont do this
My renaming the file it exists in to no longer match the class name?
[ExecuteAlways]
public class Smth : MonoBehaviour
{
private void OnEnable()
{
if (GetComponent<Rigidbody>()) // if any condition
{
Debug.LogWarning("blabla");
Destroy(this);
}
}
}
Are you adding the component at runtime (through code)?
Correct
basically default imps can result in:
"what the heck, our FooUnitTests are all breaking now, but git blame is saying FooUnity.cs hasnt been changed in several months, and we mock all our interfaces for injection of dependencies so... how the hell are the unit tests breaking now?"
That makes a lot of sense thank you
I think [AddComponentMenu(null)] or [AddComponentMenu("")] on the class should hide it in the menu.
This is cursed
empty string did the trick. It obviously is possible to still drag and drop but this is good enough, tyvm!
also e.g. you cannot add BoxCollider if gameObject has Rigidbody2D
they won't be able to create an error window like unity does though
this is also a big reason why I never use inheritance for my services. it removes the possibility of code "somewhere else" changing and breaking my unit tests that have been glass box'd.
Inheritence: Foo inherits from Bar. FooUnitTests started breaking, despite Foo.cs never being altared... reason: Bar.cs got altared.
Composition: Foo depends on an IBar, but for the unit test we use a MockBar (usually via Moq) that we inject in, that way the only code that gets tested in FooUnitTests is purely the code inside of Foo.cs
However... if Foo : IFoo and now you throw default imps into the mix... that all goes right out the window D:
but do I still have to create a class for every enum?
No, you can just add the EnumDropdown<T> directly onto a GameObject
Yes i very much know how great interfaces are, i just didn't know the details about static extension like you explained earlier
So technically yes but the library handles "automatically" generating those for you
the dropdown you have suggested?
I see
if you pick a new one itll prompt you to save the .cs file somewhere
It doesn't even prompt you
I wonder how they have done it just with c#
It's open source, you can look in there
I am too bad in generics to understand it
Well we know that it's code generation
brings back to this statement, that library is an example of "something very fancy" hahaha
It's probably just:
$"public class {ClassName}_{Type.Name} : {ClassName}<{Type.Name}> { }"
```written to a file
I.. did that just now lol
the fancier part is the nice browser of namespace/assembly, including with handling the constraints
Yeah of course
but you could a prototype with just that
and saving to a random folder
i18nKey??
I have localization for my project
I18n key just specify where to look for the translated text for each option
I18n is for internationalization (dumbest shorthand ever)
Ngl that piece of code looks very weird to me
C# before generics
this is crazy, it offers me all enums in Assembly to select from
This is before i knew about genericunityobject lol
holy shit THATS WHAT THAT MEANS?!
Yes
oh my god I have seen that so many times and I never realized thats what that was
"yea its spelled.. I uh theres 18 letters, then an N"
I always thought the I was an l
thatd be l10n!
this is up there with k8s
kates?
kubernetes
who tf..
I hate the "stick a number in the middle of it" approach
I find myself guilty for using it
I don't think I ever thought "you know what, my variables should have digits in them"
i hate it but id hate typing a 20 character word at the same time
aint no way im spelling i18n without a typo
How do I convert a Transform[] to a List<Transform>
.ToList()
.ToList()
.ToListen()
But dont to it very often because memory
got it, dont listen to people cuz I have a bad memory 😮
"Transform[] does not contain a definiton for ToList"
new List<Transform>(Transform[]) 😏
You have to add using System.Linq;
...Wouldn't that make an array of arrays
Thank you
No, that would be new List<Transform[]>()
no, the array is being passed into the parameters of the list
No that'd be new List<Transform[]>
but why does it give me a warning now?
public class DropdownEnum<T> : MonoBehaviour where T : Enum
Is the file named DropdownEnum?
Pls guys help me
yes, Dropdown.cs
wouldn't you need a separate file and class like:
LevelDiffDropdown : DropdownEnum<LevelDiff> ?
LevelDiffDropdown.cs
I exported my first charcter from blender as test, ma boy is clipping through the floor 💀
rename it to exactly DropdownEnum.cs
They're using Genericunityobject to avoid that
that's a package they have recommended me
would this be the place to ask about TMPro questions? or should i go up to the beginner?
never heard of it but I'll back off then since idk what it's about
the lib in use automatically generates that, its pretty cool
I see
Im definitely gonna add it to my toolbox, it seems super handy
Yes
depends how common vs zany of a thing you are doing with said TMP
hmm that's weird
That's what kesomannen recommended
oh, shouldn't it be like this instead?
the bottom one is right I believe
It looks like you're using quite an old version of unity. Does it meet the requirements?
Unity 2020.2 or higher
.NET 4.x (when using Unity 2021.1 or lower)
Oh no
No, the bottom one needs a type "Add ..." to be pressed
Okay I couldn't have used it anyway lol
the top one looks correct except for the warning
How do you remove a bone from a skinned mesh renderer
no, I have .NET Standart 2.1 and 2021.3 Unity version
Im sure its fairly simple. Can you turn on a UI text if you reference a gameobject?
oh, then the script's icon is messed up
why?
The warning might be a bug in the package
¯_(ツ)_/¯
Is staylow the gameobject with the text?
I see, well
That works i think
try readding the component
Thank you all for your help guys 😄 I appreciate taht
tried.
otherwise you can make your own class:
public class LevelDiffDropdown : EnumDropdown<LevelDiff> { }
do the job yourself
Or go the cursed route like that SettingsEnum.cs i sent
The debug shows it working with the collider (i have it set to trigger) but the text does not show up when i enter it
I can't set the bones to an array, so the "get list of bones, modify it, then set" isn't working
It's probably the comparetag part then
I have never used tags in unity so I can't help you
change from GameObject to a TMP_Text at the top. And then you can just enable/disable it
specifically Staylow.enabled = true/false
Is it better to toggle the component or to toggle the activeness of the gameobject
Depends
tbh I would actually expect its better to modify the culling mask of the camera :x
thats how I go about it, get as low level as possible to minimize called logic
Jesus christ lol
(can also just modify the display layer of the thing in question)
if this isnt about visibility then this doesnt do anything
it is indeed visibility
stuff like sprites and canvas and whatnot
It's still not toggling, i Thinkbuddy was right and the Tags might be the issue
But if the canvas is overlay mode then it doesnt work right?
still works, your camera has a bitmask for what it can "see" vs not
Why are you comparing tags though, what's the idea
ah i couldnt find the context scrolling up
breakpoint in the method and attach the debugger, see whats up
That if a helicopter goes too high they get a warning before they die
still works for me even if I disable my camera
the component would be faster to disable
ill try removing the tags
wait what, really? huh.
But if you have children that could be weird
That has never been a performance issue for me but that's cool
really depends on what you want
from my experience though, its never really been a choice vs component or whole object, because of the different use cases
yeah like if its a button you prolly wanna disable the whole object, cuz the text of the button is a child
though I think the canvas button has a method to handle this?
UI is not render through the camera.
- depends on the canvas mode
It shouldn't display anything in play mode i think
it does
Huh
Can anyone help with removing a bone from a skinned mesh renderer :(
I can't really help, but did you see this thread?
https://forum.unity.com/threads/problem-removing-bones-from-a-skinnedmeshrenderer-at-runtime.204746/
Yes
I don't have any experience with these so can't help you
Obviously
what you see in the game view is what you'll pretty much see in play mode, it does display still.
Ah right i forgot
Yeah canvas without camera will just render in overlay mode okay
i think the "No cameras rendering" is the exception, or you can toggle if its shown i forget the specifics
Got it working, thanks guys! mixture of the Tags and then using TMP_text. heres the end result
that OnTriggerEnter is definitely bugged
it's going to happen regardless of the tag
Just warning you that the if statement is only guarding the debug.log
because of where you put the log
i just moved around the bug on the "ascent" and seeing if it was they tag that was giving me the error, turns out the tag was wrong and i reverted it back to the play and had no issues
what
idk what "ascent" is
but your if statement is structured incorrectly
that's all we're saying
you need to swap the { and the Debug.Log lines
You probably want Staylow to activate only when the tag match from the looks of it
And that's not the case right now
ahh i see what you're saying
Still can't figure out bone removal :(
I really don't know how to help you
The only thing i can say is best of luck looking for a solution
Yeah I'm asking people here who might know more, not specifically you
Thank you though
Working with unity can be frustrating like that sometimes
Last time i went insane because unity's inputfield implementation was so bad I had to extend it myself and modify the behaviour (i even used reflection to modify a private variable)
is the [defaultexecutionorder] attribute reliable on all platforms?
APPLE SIGN IN ICW PLAYFAB
Today I finished an update for the Android version of my game.
And tomorrow I will go back to the Apple IOS version.
Now the behavior, shop stuff etc works fine, but last time I tried, I really got stuck with the mandatory Apple Sign in and the fact that you have to push everything through XCode does not make it any easier ...
So I was wondering if anyone here had any experience with this specific issue and if they could give some pointers or links to resources (preferably a video where someone shows how it works) .
Then hopefully , if (and probably when) I get stuck with this (BLEEP) again, I have some straws to pull on 🙂
As always thanks in advance!!!
if i wanted to make a AR and VR game. would it be better to work on the same project but in different scenes, or should i just make individual projects for both. Also they would both work the same. same scripts assets, etc
You might get better help here
https://discord.com/channels/489222168727519232/497874498373156894
And here
https://discord.com/channels/489222168727519232/497874524549808128
alright thanks
it's called ClassTypeReferences
it serializes the identity of a class into an object of type TypeReference, and also lets you narrow the scope. Such as only allowing types that derive from a given baseclass, or implement a certain interface.
no bullshit typing strings, either. All type names get validated, so no spelling errors.
it uses reflection, obvs
Serializing type is easy. Type.AssemblyQualifiedName is a string, that is all you need
[field: SerializeField] public ClassTypeReference tileMono { get; private set; }```
Cool. So you can do that in even less effort?
I see no Type there
tileMono is an object with a Type field
tileMono.Type is the type that it corresponds to
and it comes with a property drawer
so
ClassTypeReference<TileMonobehaviour> tileMono
would not do the same?
TypeReference is not a generic
why not?
if it's using reflection it should be
this is a typical c++ hack for something that c# solved long ago
actually I don't see System.Reflection. I thought Type was in the reflection namespace
so it doesn't use reflection
Eh, it's the entry point to Reflection. Pretty much everything in it is Reflection.
so ClassTypeReference does NOT use System.Reflection. The property drawer DOES
I assume this is so it can be fast as shit during runtime
It's still serializing a string, and needs to use Reflection to resolve the type from the string.
that's what I assume is going on
that it uses reflection only in editor
anyway. it works great. super simple. strong recommend
Hi lovely ppl. I wanna ask you for help. Im making a little raft where the player can move freely and control the boat when interacting with the steer by pressing e. Does anyone know any type of video tutorial for a almost complete beginner on how to enter/exit a vehicle and how to steer the boat by rotation? Pls DM or poke me, I would be really gratful 
hi, i have a question, why if i decelerate a 5 elements array (public bool[] cd = new bool[4];) unity says no and make it 4, crashing the game when i try to change it via teh editor
what is decelerate a 5 element array ?
im guessing that is supposed to mean declare
Count starts from zero
That's a four element array 0-3
5 elements array but you wrote new bool[4]; which is the size
4 is the length (delimiter)
damm i see i have a problem with teh names
the important take away is taht arrays start from index 0
this entirely depends on your game, you could probably something similar by looking at entering/leaving car tutorials. Pretty sure ive seen a few of those existing
Though theres so many different ways of movement, you'll likely not find something thats exactly what you want
5 elements
but unity editor only displays 4
u wrote 4
yes because you wrote new bool[4], which is the size
as size
this should be inside #💻┃code-beginner
we understand and we are telling you whats wrong!
That's four elements
thats teh problem
.
so write 5..
thats teh problem
i feel like this is a troll
5 would be bool[5]
i write 5 and it doesnt change
cause it already serialized with 4
i can write 5000 and still 4
That's simply the defaults
You'll have to reset the component or modify it from the inspector
what defaults
when you serilized it in the inspector
if i modify from teh inspector teh game crashes
When you create the instance (add the component), the default values are used.
can you show video
Thereafter, they're independent of the default values assigned during declaration
i dont have any tool
wana call??
Unless you're doing so during runtime or it's an editor script, this should not be so.
or use windows screen recorder or OBS
istalling
which version of unity btw
2021.3.25f1
not, i do it before
Can anyone help me?
It shouldn't crash then unless you've got assets that are doing improper stuff with serialization
idk tried now with other array and isnt happening
This is the coding channel, you might get more help in #💻┃unity-talk
K thx
i didnt touched nothing, and now its solved, should this be a bug report?
what could be the reason that like 1/10 times my code work and the other times not. im not clicking anything and right after starting im getting argumentNullException Value cannot be null
We'll not know without seeing the errors and code.
i have two thousand lines of code🙃
probably a gameobject whit nothing assigned
It could just be the statement cs if (Random.value < 0.1f) Crash();
dont miss the semicolon
would get recognized by the ide(rider for me), wouldnt it?
will check again
but why would it work then flawlessly sometimes
if teh editor know there is a missing semicolon, why dont put the semicolon
How could we possibly know?
So, why is my Player-layer object apparently treating another player-layer object as a collision-layer object? When player-layers, according to my physics2D settings, players can only interact with collision, not themselves.
No, there isn't a known issue that's specific to your case that you've not told us about yet that's happened before.
are you missing a collider that's still set to the other layer?
just wanna know some typical error causes like not assigning any delegate functions in the awake function when referencing another object
I don't think so. I've checked over numerous times now.
it doesnt say theres a missing semicolon. it wouldnt compile then
It's likely your fault and not Unity. It's just easier to blame the API when things aren't working as expected.
some children are on default layer but that shouldn't collide with anything given my settings
i never blamed unity. just asking for help here
if any of the children have colliders, then that would cause it. if you are using raycasts in any part of your code, you may be missing a layermask
(assuming the children with colliders are on the default layer)
Race Condition
We cannot help you without information. Randomly crashes 10% of the time without further context implies "is this a Unity issue" which can be yes or no - likely not though.
Thats usually a race condition, Id bet on it
Whats the line of code that is throwing the null exception?
NRE means something was null
see. i didnt know thats a thing. thanks a lot
they do not, only the player and collision objects have colliders. And I have castfilters for checking walls and ground that filter out the player.
its likely a race condition between 2 things.
Thing 1 assigns the value
Thing 2 tries and uses it.
If sometimes rarely Thing 2 wins the race... NRE
I haven't seen the error or code. It can be anything at this point.
then I'm out of ideas without source code/video or something
building off of this, if you aren't using both the awake and start methods to order initialization of components and accessing things on other components, that might be the problem
RELEVANT: Three layers are made for this project atm. Player, Collision, and Floor Collision. Player objects use the Player layer, collision meant to be stood on goes on the Floor Collision layer, and walls are tied to the Collision layer. groundFilter only focuses on Floor Collision and wallFilter only focuses on Collision.
public ContactFilter2D groundFilter;
public ContactFilter2D wallFilter;
private float groundDistance = 0.05f;
[SerializeField] private float wallDistance = 0.2f;
private float ceilingDistance = 0.05f;
[SerializeField] private float wallBuffer;
CapsuleCollider2D touchingCol;
RaycastHit2D[] groundHits = new RaycastHit2D[5];
RaycastHit2D[] wallHits = new RaycastHit2D[5];
RaycastHit2D[] ceilingHits = new RaycastHit2D[5];
CapsuleCollider2D touchingCol;
private void FixedUpdate()
{
IsGrounded = touchingCol.Cast(Vector2.down, groundFilter, groundHits, groundDistance) > 0;
IsOnWall = touchingCol.Cast(wallCheckDirection, wallFilter, wallHits, wallDistance) > 0;
IsOnCeiling = touchingCol.Cast(Vector2.up, groundFilter, ceilingHits, ceilingDistance) > 0;
}``` (I'd include an error message but it's semantic)
https://pastecode.io/s/5tufa5mg thats one part of it
this is why I heavily avoid using Awake/Start on monobehaviors, if I have to sit and start specifying what order stuff happens in, that way lies spaghetti town
sorry, I haven't done much with 2d.
could someone else help Zwataketa out?
Self initialization in Awake and acquiring data from others in Start should be enough to avoid most race conditions.
define "treat", like they are rigidbody colliding?
It's an Editor serialization error #↕️┃editor-extensions
And specifically with use of the Find statement
Which can very likely return null
I prefer more finessed control where I use methods being called by 1 single orchestration overhead to drive everyone else, therefore the order things get called in is explicitly defined by the stack trace itself